使用composer为Symfony2设置MongoDb

Joa*_*nne 3 annotations mongodb symfony

我是Symfony2的新手,我已经按照Symfony2网站上的指南使用composer安装了MongoDb Doctrine包(这也是我安装Symfony2的方法)

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

我将这些行添加到app/autoload.php中:

use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
AnnotationDriver::registerAnnotationClasses();
Run Code Online (Sandbox Code Playgroud)

和app/AppKernal.php

new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
Run Code Online (Sandbox Code Playgroud)

在指南中提出,但当我尝试加载Symfony应用程序(这只是演示应用程序)时,我收到以下错误:

InvalidArgumentException: The service definition "doctrine_mongodb.odm.document_manager" does not exist.
Run Code Online (Sandbox Code Playgroud)

[还有更多的痕迹,让我知道这是否有用]

如果我注释掉我添加到app/AppKernal.php的行,那么Symfony Demo应用程序加载没有问题.

我运行了app/check.php,我注意到以下警告:

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.
Run Code Online (Sandbox Code Playgroud)

我目前正在使用Ubuntu(5.3.5-1ubuntu7.11)附带的PHP版本,它看起来像上面的composer/mongodb位使用Annotations.

当我进行谷歌搜索时,我找不到任何明显的东西,并认为如果我的PHP版本确实存在问题,这将更常见.

据我所知,我需要:

  • 从源代码编译PHP到升级到5.3.8
  • 不使用composer安装Symfony2,因为看起来安装MongoDB软件包的旧方法不使用注释
  • 我完全错过了一些东西,因为我不知道Symfony2是如何工作的:D

有没有人有任何建议或其他解决方案更容易?如果可以的话,我真的很想坚持作曲家.

Sgo*_*kes 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
Run Code Online (Sandbox Code Playgroud)