Simple storage for images.
Add to your composer.json
:
{
"require": {
"fullpipe/image-bundle": "dev-master"
}
}
And to AppKernel.php
:
// app/AppKernel.php
class AppKernel extends Kernel
{
//...
public function registerBundles()
{
$bundles = array(
//...
new Fullpipe\ImageBundle\FullpipeImageBundle()
);
return $bundles;
}
//...
}
fullpipe_image:
web_root: /media/image //Web directory
data_root: %kernel.root_dir%/../web/media/image //Directory for storing images
First you need to extend Fullpipe\ImageBundle\Entity\Image
by you own entity.
For example we have Acme\BannerBundle\Entity\Banner
//Acme/BannerBundle/Resources/config/doctrine/Banner.orm.yml
Fullpipe\BannerBundle\Entity\Banner:
type: entity
table: acme_banner
lifecycleCallbacks: { }
and our entity
//Acme/BannerBundle/Entity/Banner.php
namespace Acme\BannerBundle\Entity;
use Fullpipe\ImageBundle\Entity\Image;
/**
* Banner
*/
class Banner extends Image
{
}
after this we need to update BannerType.php
//Acme/BannerBundle/Form/Type/BannerType.php
namespace Acme\BannerBundle\Form\Type;
use Fullpipe\ImageBundle\Form\Type\ImageType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Banner type.
*/
class BannerType extends ImageType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
//...
parent::buildForm($builder, $options);
//..
}
}
that's all
To get web path to original image use web_path
twig filter.
<img src="{{ banner|web_path }}" />
-> /media/image/some_path.png
With LiipImagineBundle
Do not forget to use same data_root
directory
...
liip_imagine:
...
loaders:
default:
filesystem:
data_root: %kernel.root_dir%/../web/media/image
...
- tests
- model abstraction