[SonataMediaBundle] PHP Fatal error: Class 'Sonata\MediaBundle\SonataMediaBundle' not found in /app/AppKernel.php on line 25

1,512 views
Skip to first unread message

dao bao ngoc

unread,
Jun 24, 2013, 5:27:55 AM6/24/13
to sonata...@googlegroups.com
Hey,

I'm new with Symfony 2 and i'm getting a lot of trouble when try to get SonataMediaBundle working...

I use Symfony 2.3.1 and follow step by step guides from http://sonata-project.org/bundles/media/master/doc/reference/installation.html

But at that step to run the below command:
php app/console sonata:easy-extends:generate SonataMediaBundle
I always get the error:
PHP Fatal error:  Class 'Sonata\MediaBundle\SonataMediaBundle' not found in /media/datas/websites/trolley/app/AppKernel.php on line 25

I sure i follow correctly all steps:
- Registered in registerBundles:
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
         new Sonata\BlockBundle\SonataBlockBundle(),
        new Sonata\CacheBundle\SonataCacheBundle(),
new Sonata\jQueryBundle\SonatajQueryBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\MediaBundle\SonataMediaBundle(),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),   
...
- config.yml
sonata_media:
    # if you don't use default namespace configuration
    #class:
    #    media: MyVendor\MediaBundle\Entity\Media
    #    gallery: MyVendor\MediaBundle\Entity\Gallery
    #    gallery_has_media: MyVendor\MediaBundle\Entity\GalleryHasMedia
    providers:
        image:
            resizer: sonata.media.resizer.square    
    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
                    
...
# Doctrine Configuration
doctrine:
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true
        entity_managers:
            default:
                mappings:
                    SonataMediaBundle: ~
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
...

- routing.yml

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

media:
    resource: '@SonataMediaBundle/Resources/config/routing/media.xml'
    prefix: /media

I used "dev-master" to get the bundle:
php composer.phar require sonata-project/media-bundle
=>
dev-master
php composer.phar update

I really appreciate any help!

Best,


Jakala

unread,
Jun 24, 2013, 1:02:05 PM6/24/13
to sonata...@googlegroups.com
hello:

maybe you forget to install vendors with composer???

it appears that vendor/sonata-project/media-bundle does not exist...

dao bao ngoc

unread,
Jun 25, 2013, 3:59:21 AM6/25/13
to sonata...@googlegroups.com
Hi,

Thanks for your thoughts!

> maybe you forget to install vendors with composer???
=>
I think with the latest Symfony 2 version (2.3.1 that i'm using), run the command line:

php composer.phar require sonata-project/media-bundle
=>
Enter: dev-master
php composer.phar update

will install the vendor automatically ?

And i can see the bundle "media-bundle" in the folder vendor/sonata-project

I finally can solve the problem. Post here if anyone has the same issue.

The problem is the composer doesn't re-create auto-load files/definitions for the bundle, so we have to declare it manually in the composer.json first, to suggest the composer create these auto-loads
    "autoload": {
"psr-0": { 
                         ...
"media-bundle": "vendor/sonata-project",
"Application": "app/",
 ...
}
},

Then i can run the command line 
php app/console sonata:easy-extends:generate SonataMediaBundle
and follow other steps without any problem!

Best,
Reply all
Reply to author
Forward
0 new messages