dev-master
9999999-dev http://github.com/avro/ImageBundleSymfony2 image Bundle
MIT
The Requires
- php >=5.3.2
by Joris de Wit
image
Symfony2 image Bundle
Symfony2 Image Bundle., (*1)
Easily attach images to any object and display them as a gallery, carousel, or lightbox., (*2)
Add AvroImageBundle in your composer.json:, (*3)
{ "require": { "avro/image-bundle": "*" } }
Now tell composer to download the bundle by running the command:, (*4)
``` bash $ php composer.phar update avro/image-bundle, (*5)
### Enable the bundle in the kernel: ``` php // app/AppKernel.php new Avro\ImageBundle\AvroImageBundle
//app/config/routing, (*6)
``` yaml avro_image: resource: "@AvroImageBundle/Resources/config/routing/routing.xml", (*7)
### Add Resources Add CSS ``` html {% stylesheets output='css/compiled/app.css' filter='cssrewrite, less, ?yui_css' ... 'bundles/avroimage/css/avro-image.css' ... %} <link rel="stylesheet" href="{{ asset_url }}" type="text/css" media="screen" /> {% endstylesheets %}
Add JS ``` html {% javascripts output='js/compiled/app.js' filter='?yui_js' ... 'bundles/avroimage/js/avro-image.js' ... %} {% endjavascripts %}, (*8)
Dump your assets and watch ``` bash $ php app/console assets:install --symlink=true $ php app/console assetic:dump --watch --force
Add the image reference to the object you want to rate, (*9)
``` php <?php // src/Acme/ProductBundle/Document/Product.php, (*10)
namespace Acme\ProductBundle\Document;, (*11)
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Avro\ImageBundle\Model\ImageObjectInterface;, (*12)
/** * @ODM\Document */ class Product implements ImageObjectInterface { ..., (*13)
public function __construct() { $this->images = new \Doctrine\Common\Collections\ArrayCollection(); } /** * @ODM\ReferenceMany(targetDocument="Avro\ImageBundle\Document\Image", cascade={"all"}, sort={"position"="asc"}) */ protected $images; /** * Set images * * @param ArrayCollection $images * @return Product */ public function setImages(\Doctrine\Common\Collections\ArrayCollection $images) { $this->images = $images; return $this; } /** * Get images * * @return MongoCursor $images */ public function getImages() { return $this->images; } /** * Add images * * @param Avro\ImageBundle\Document\Image $image */ public function addImage(\Avro\ImageBundle\Document\Image $image) { $this->images[] = $image; return $this; } /** * Remove image * * @param Avro\ImageBundle\Document\Image $image */ public function removeImage(\Avro\ImageBundle\Document\Image $image) { $this->images->removeElement($image); return $this; } /** * Get the documents name */ public function getDocumentName() { return 'product'; } ...
}, (*14)
Configuration Reference ----------------------- ``` yaml avro_image: db_driver: mongodb carousels: my_carousel: style=twitter width: 300 height: 300 slide: true my_custom_carousel: style: custom template: AcmeDemoBundle:Carousel:my_carousel.html.twig
Render images in twitter bootstrap carousel, (*15)
html
{{ carousel_render('twitter', product.images) }}
, (*16)
And that's it!, (*17)
Send in your custom templates!, (*18)
Symfony2 image Bundle
MIT
image