我在这里经常看到同样的错误,并且已经阅读并根据之前的问题和答案进行了更改,但无济于事。
我已经通过 Composer 使用 Zend Framework 安装了 Doctrine 的 Mongo ODM,并按照此处所述完成了安装
https://github.com/doctrine/DoctrineMongoODMModule
我已经修改了我的 /config/autoload/module.doctrine-mongo-odm.local.php 文件,超出了上述文档的建议,以解决我的问题,并根据此处对类似问题的回答,现在看起来像跟随
<?php
return array(
'doctrine' => array(
'connection' => array(
'odm_default' => array(
'server' => 'removed.mongolab.com',
'port' => '43957',
'user' => 'removed',
'password' => 'removed',
'dbname' => 'richard',
'options' => array()
),
),
'configuration' => array(
'odm_default' => array(
'metadata_cache' => 'array',
'driver' => 'odm_default',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineMongoODMModule/Proxy',
'proxy_namespace' => 'DoctrineMongoODMModule\Proxy',
'generate_hydrators' => true,
'hydrator_dir' => 'data/DoctrineMongoODMModule/Hydrator',
'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
'default_db' => 'richard',
'filters' => array(),
'logger' => null
)
),
'odm_default' => array(
'drivers' => array(
'Application\Document' => 'odm_driver'
)
),
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'module/Application/src/Application/Document'
),
),
'documentmanager' => array(
'odm_default' => array(
'connection' => 'odm_default',
'configuration' => 'odm_default',
'eventmanager' => 'odm_default'
)
),
'eventmanager' => array(
'odm_default' => array(
'subscribers' => array()
)
),
),
);
我有一个文件 /module/Application/src/Application/Document/User.php 如下
<?php
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations;
class User {
/** @ODM\Id */
private $id;
/** @ODM\Field(type="bin_data_timestamp") */
private $timestamp;
/** @ODM\Field(type="string") */
private $username;
/** @ODM\Field(type="bin_data_md5") */
private $password;
/** @ODM\Field(type="bin_data_uuid") */
private $salt;
/** @ODM\Field(type="string") */
private $realName;
/** @ODM\Field(type="string") */
private $email;
public function getId() {
return $this->id;
}
// ...
public function setId($id) {
$this->id = $id;
}
// ...
}
在我的控制器中,我使用以下代码。
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$user = new User;
$user->setUsername("test");
$dm->persist($user);
$dm->flush();
但是,我遇到了臭名昭著的错误
The class 'Application\Document\User' was not found in the chain configured namespaces
任何帮助将不胜感激。