DoctrineMongoDBBundle getting a fatal error in Symfony2
Asked Answered
B

1

11

I'm following the directions here: http://symfony.com/doc/2.0/bundles/DoctrineMongoDBBundle/index.html

I have installed deps:

#deps
[doctrine-mongodb]
    git=http://github.com/doctrine/mongodb.git

[doctrine-mongodb-odm]
    git=http://github.com/doctrine/mongodb-odm.git

[DoctrineMongoDBBundle]
    git=http://github.com/symfony/DoctrineMongoDBBundle.git
    target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle

then did $ php bin/vendors install

I added the following:

# app/autoload.php
$loader->registerNamespaces(array(
    // ....
    'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
    'Doctrine\\DBAL'   => __DIR__.'/../vendor/doctrine-dbal/lib',
    'Doctrine\\ODM\\MongoDB'    => __DIR__.'/../vendor/doctrine-mongodb-odm/lib',
    'Doctrine\\MongoDB'         => __DIR__.'/../vendor/doctrine-mongodb/lib',
    'Doctrine'         => __DIR__.'/../vendor/doctrine/lib',
    // ....
));

AnnotationRegistry::registerFile(
    __DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
);
AnnotationRegistry::registerFile(
    __DIR__.'/../vendor/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php'
);

I also added

# app/AppKernel.php
$bundles = array(
    //....
    new Symfony\Bundle\DoctrineMongoDBBundle\DoctrineMongoDBBundle(),
    //....
);

And my doctrine configuration looks like:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options:
                connect: true
    default_database: dbtest
    document_managers:
        default:
            auto_mapping: true

But when I load the app I get the following error:

Fatal error: Class 'Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension' not found in /Volumes/Master/SITES/example/vendor/bundles/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php on line 31

Call Stack:
    0.0002     643984   1. {main}() /Volumes/Master/SITES/example/web/app_dev.php:0
    0.0175    5274704   2. Symfony\Component\HttpKernel\Kernel->handle() /Volumes/Master/SITES/example/web/app_dev.php:31
    0.0176    5274800   3. Symfony\Component\HttpKernel\Kernel->boot() /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:168
    0.0212    5592040   4. Symfony\Component\HttpKernel\Kernel->initializeContainer() /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:127
    0.0232    5662744   5. Symfony\Component\HttpKernel\Kernel->buildContainer() /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:545
    0.0430    8473952   6. Symfony\Bundle\DoctrineMongoDBBundle\DoctrineMongoDBBundle->getContainerExtension() /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:630
    0.0430    8474568   7. Symfony\Component\ClassLoader\DebugUniversalClassLoader->loadClass() /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php:0
    0.0437    8623704   8. require('/Volumes/Master/SITES/example/vendor/bundles/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php') /Volumes/Master/SITES/example/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php:55

My app was using MySQL but I want to evaluate mongodb.

Burberry answered 2/11, 2011 at 18:13 Comment(0)
B
26

Try fixing the bundle's version:

[DoctrineMongoDBBundle]
    git=http://github.com/symfony/DoctrineMongoDBBundle.git
    target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
    version=v2.0.0

And remember to always use bin/vendors install — not bin/vendors update. Unless you are developing Symfony itself, of course.

Bodnar answered 2/11, 2011 at 18:56 Comment(3)
I've been using this bundle for a couple of months and it stopped working today after I ran bin/vendors install to update bundles. So I figured that developers changed something. Since I was on master, it was only a matter of time. So I looked up a tag in the bundle's repo and sticked to it.Bodnar
bin/vendors update can also be used if you wish to freeze bundle versions, say, for a release of your app.Nazar
This really helped. I also needed to add the config from symfony.com/doc/current/bundles/DoctrineMongoDBBundle/… for the sample config. Even if it is an invalid config to DB that isn't accessible.Silassilastic

© 2022 - 2024 — McMap. All rights reserved.