Sonata – Install MediaBundle

Composer install

Installation

Execute:

composer require sonata-project/media-bundle --no-update
composer require jms/serializer-bundle --no-update
composer require sonata-project/intl-bundle --no-update
composer update

Add in app/AppKernel.php

# app/AppKernel.php
public function registerBundles()
 {
    $bundles = array(
        /.../
        // MediaBundle
        new Sonata\MediaBundle\SonataMediaBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new Sonata\IntlBundle\SonataIntlBundle(),
        /.../
}

Add in app/config/routing.yml

# app/config/routing.yml
gallery:
    resource: '@SonataMediaBundle/Resources/config/routing/gallery.xml'
    prefix: /media/gallery
media:
    resource: '@SonataMediaBundle/Resources/config/routing/media.xml'
    prefix: /media

Add in /app/config/config.yml

# app/config/config.yml
sonata_media:
    default_context: default
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
    contexts:
        default: # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
            formats:
                small: { width: 100 , quality: 70}
                big: { width: 500 , quality: 70}
    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/
    filesystem:
        local:
            directory: %kernel.root_dir%/../web/uploads/media
            create: false

Execute :

# php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

Add in app/AppKernel.php

# app/AppKernel.php
public function registerBundles()
 {
    $bundles = array(
        /.../
        // MediaBundle
        new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
        /.../
}

Update database

# php app/console doctrine:schema:update --force

Create media directory

mkdir web/uploads
mkdir web/uploads/media
chmod -R 777 web/uploads

Set the web_dir

Add in app/parameters.yml:

parameters:
    /.../
    web_dir: http://yourwebsite.ext/

then add in app/config.yml

sonata_media:
    cdn:
        server: 
            path: %web_dir%/uploads/media

 

 

Command lines

Regenerate images

# php app/console sonata:media:sync-thumbnails sonata.media.provider.image default

Raphaël has written 45 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>