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