设置ZF2+ODM时,出现以下错误:
The class 'Application\Document\User' was not found in the chain configured namespaces
当前设置如下:
ZF2稳定,通过composer.phar安装条令odm,包含composer.json的内容
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"minimum-stability": "dev",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.0.0",
"doctrine/doctrine-mongo-odm-module": "dev-master"
}
}
加载的模块
'modules' => array(
'Application',
'DoctrineModule',
'DoctrineMongoODMModule',
),
创建水合器和代理目录
$ ls -l data/DoctrineMongoODMModule/
total 0
drwxrwxrwx 2 wisu staff 68 Sep 12 08:34 Hydrators
drwxrwxrwx 2 wisu staff 68 Sep 12 08:35 Proxy
ODM配置看起来像
'driver' => array(
'odm_default' => array(
'drivers' => array(
'Application\Document' => 'aplikasi'
)
),
'aplikasi' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'module/Application/src/Application/Document'
)
)
),
我正在尝试使用以下映射
<?php
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** @ODM\Document(collection="user") */
class User
{
/** @ODM\Id */
private $id;
/** @ODM\Field(type="string") */
private $name;
/**
* @return the $id
*/
public function getId() {
return $this->id;
}
/**
* @return the $name
*/
public function getName() {
return $this->name;
}
/**
* @param field_type $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* @param field_type $name
*/
public function setName($name) {
$this->name = $name;
}
}
但是通过
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Document\User;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$user = new User();
$user->setName("Gembul");
$dm->persist($user);
$dm->flush();
return new ViewModel();
}
}
有什么建议吗?
最佳答案
真正的解决方案不是将module.district-mongo-odm.local.php添加到autoload目录中,这几行对我来说是配置。
'driver' => array(
'ODM_Driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../../module/Application/src/Application/Doctrine/Document')
),
'odm_default' => array(
'drivers' => array(
'Application\Doctrine\Document' => 'ODM_Driver'
)
),
),