0
使用zend 2与标准的应用程序结构。 我有实体:doctrine 2 setHydrator错误
module\University\src\University\Entity\Student.php
<?php
namespace University\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="students")
*/
class Student
{ //more stuff
}
和形式
University\src\University\Form\StudentForm.php
<?php
namespace University\Form;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Form;
use Zend\ServiceManager\ServiceManager;
class StudentForm extends Form
{
parent::__construct('student-form');
$entityManager = $serviceManager->get('Doctrine\ORM\EntityManager');
$this->setHydrator(new DoctrineHydrator($entityManager, 'University\Entity\Student')); // this row cause the error
// more stuff
}
在控制器:
<?php
namespace University\Controller;
use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel,
University\Entity\Student,
University\Form\StudentForm;
class StudentController extends AbstractActionController
{
public function indexAction()
{
$form = new StudentForm($this->serviceLocator);
// more stuffs
}
}
和学说抛出我的错误:
File:
\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:38
Message:
The class 'University\Entity\Student' was not found in the chain configured namespaces \Entity
IM以下this教程。
任何想法,为什么我得到这个错误,以及如何解决它?
编辑 我发现如何解决这个问题,以及为什么造成这个问题。答案转移到主题答案中。'
第一次猜测:原理错误的驱动程序配置。由于错误,我的绝对猜测是''namespace University;'在doctrine-config中缺少。 – Sam 2013-02-11 19:41:11
确实。 @Tudor请粘贴相关配置(https://github.com/doctrine/DoctrineORMModule自述文件中的一个) – Ocramius 2013-02-11 21:09:21
嗨,大家好,感谢您的快速响应,并对我的慢速回复感到抱歉:> 您说得对,我懂了现在工作,但用这个配置在module.config.php(即时编辑主帖) – Todor 2013-02-12 08:36:42