Skip to content

How to add the Sonata Media Bundle

Robert H. Speer edited this page Jan 29, 2014 · 1 revision

Freshness:

This method for installing the Sonata Media Bundle into the Sonata Distribution was successfully completed on January 29th, 2014, eventually they won't work anymore. At that time please figure it out and update the Wiki, only you can prevent bad documentation.

Intro:

The Sonata Media Bundle is an off the shelf module for uploading, performing basic parsing on, storing, & displaying media.

It's also really easy to add to this Sonata Distribution, assuming the following adjustments to the standard instructions are used.

Installation Updates:

Default install Doc: http://sonata-project.org/bundles/media/master/doc/reference/installation.html

The default doc is very close so this document will just highlight the differences.

Composer changes:

  1. skip adding the doctrine-orm-admin-bundle, it's already in the distribution
  2. when asked for a version for the media-bundle, 2.2.6 is known to work, failing that try dev-master

app/AppKernel.php registerBundles changes

  1. at the time of writing this doc the SonataCoreBundle() was just getting started and 2.2.6 did not use it yet, so skip that
  2. also skip the SonataEasyExtendsBundle() because it's already part of the distribution

Routing

  1. add the routing to app/config/routing_sonata.yml - The _sonata is just a convention to keep the config files more organized

Config

  1. doctrine: skip adding entity_mappers, @fabpot made this redundant with "auto_mapping: true", see this blog post: http://symfony.com/blog/symfony2-getting-easier
  2. doctrine_phpcr: also safe to skip
  3. sonata_media: add this to app/config/config_sonata.yml, again just separated out to keep the files organized.

Generate Entities

  1. add "--dest=src" like so:

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

This will put the generated code next to the UserBundle already in the distribution, and have it picked up by the autoloader, instead of giving you cryptic errors that take hours and hours to diagnose. Not that I'm bitter ;)

AppKernel.php registerBundles() part 2

  1. register the bundle as normal, but put it after the distribution's user bundle, grouping generated sonata module just for OCD style points.

config.yml part 2

  1. once again you can ignore the entity mappers through the magic of "auto_mapping: true"

updating your database

  1. only do this on dev, after you backup:

    app/console doctrine:schema:update --force

It adds the tables you'll need to make the Sonata Media Bundle go

directory & permissions

  1. no changes

Environmental concerns:

  1. make sure you php.ini allows your app to handle big image sizes both for uploading and for processing into smaller sizes
  2. make sure GD is installed and the extension is turned on in your PHP install
  3. stuff's going to work a little better if you go ahead and set up a local url, not a big deal.
  4. remember to restart apache if you're still using it.