使用带有标准应用程序结构的zend 2。我有实体:
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
我正在关注本教程。
任何想法为什么我得到这个错误以及如何解决它?
编辑 我找到了如何解决这个问题以及它为什么引起的。答案被移动到主题答案中。