3

I'm very new to Symfony2, I have followed the guide on the Symfony2 website to install the MongoDb Doctrine bundles using composer (which is also how I installed Symfony2)

http://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/index.html

I added the lines into app/autoload.php:

use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
AnnotationDriver::registerAnnotationClasses();

and app/AppKernal.php

new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),

that were suggested in the guide, but when I try to load the Symfony app (which is just the Demo app) I get the following error:

InvalidArgumentException: The service definition "doctrine_mongodb.odm.document_manager" does not exist.

[And a lot more trace, let me know if this would be useful]

If I comment out the line I added into app/AppKernal.php then the Symfony Demo app loads with no problems.

I have run app/check.php and I noticed the following warning:

WARNING  When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156
          Install PHP 5.3.8 or newer if your project uses annotations.

I am currently using the PHP version shipped with Ubuntu (5.3.5-1ubuntu7.11) and it looks like the composer/mongodb bits above use Annotations.

I can't find anything obvious when I do a Google search and assumed this would be more common if it's really a problem with my PHP version.

From what I can tell I will need to either:

  • Compile PHP from source to upgrade to 5.3.8
  • Install Symfony2 not using composer, as it looks like the old way of installing the MongoDB bundles doesn't use annotations
  • I've totally missed something because I have no idea how Symfony2 works :D

Does anyone have any suggestions or other solutions that would be easier? I'd really like to stick with composer if I can.

4
  • Upgrade your Ubuntu to 12.10 — it ships with PHP 5.4. Or — if you can't do that now — use a PHP PPA like this one. Commented Oct 26, 2012 at 6:54
  • 2
    Did you add the necessary config to you config.yml file? Commented Oct 26, 2012 at 7:15
  • I didn't add anything to config.yml, but I haven't tried to connect to any database yet, I was literally just loading the Demo page, I'd not written any Symfony code yet. Commented Oct 26, 2012 at 8:33
  • I'll look into upgrading my Ubuntu that might help, ty for your answers Commented Oct 26, 2012 at 8:33

2 Answers 2

9

I don't know about the PHP version (there might be a problem there, but the error you get doesn't say something about it explicitly), but your problem is the missing configuration in your config.yml.

You must add this even if you don't use the service right now. It does not even have to be valid information, it just must be present.

Add the following to your config.yml (copied from here):

# app/config/config.yml
doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options: {}
    default_database: test_database
    document_managers:
        default:
            auto_mapping: true
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, that has fixed it. Thank you so much! Lesson learnt, always finish a guide to the end!
Every bundle defines the config parameters which must be set. If Doctrine ODM defines that there must be a connection defined than symfony will fail if this is not the case.
0

Symfony works well with DoctrineMongoDBBundle installed via composer. Installing dependencies using composer it's the best practice.

You have to update your php to 5.4.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.