我按照the cookbook中描述的步骤操作。但是当我运行doctrine:mapping:info
或doctrine:generate:entities
时,我的文件会忽略我的文件。
这是代码,也许有人有建议。
autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* @var $loader ClassLoader
*/
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
AnnotationDriver::registerAnnotationClasses();
return $loader;
composer.json
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/mongodb-odm": "1.0.*@dev",
"doctrine/mongodb-odm-bundle": "3.0.*@dev",
"doctrine/doctrine-bundle": "1.2.*",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
config.yml:
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: test_database
document_managers:
default:
auto_mapping: true
实体:
<?php
// src/Acme/StoreBundle/Document/Product.php
namespace Anchorbrands\Bundle\LandingpageBundle\Entity;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Product
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\String
*/
protected $name;
/**
* @MongoDB\Float
*/
protected $price;
}
答案 0 :(得分:3)
namespace Anchorbrands\Bundle\LandingpageBundle\Entity;
应该是
namespace Anchorbrands\Bundle\LandingpageBundle\Document;
文档通常位于 Document 文件夹中。
实体文件夹/命名空间用于ORM而不是ODM。
查看文档here。
错误的命令
对于mongodb / doctrine odm你需要使用......
app/console doctrine:mongodb:generate:documents AnchorbrandsLandingpageBundle
......而doctrine:generate:entities
是为了教条主义。