【发布时间】:2013-12-18 16:29:59
【问题描述】:
我在 Zend Framework 2 项目中使用 Doctrine 2 ORM。
我试图坚持多对多的关系。我遵循了描述here(manytomany)的文档。
在尝试持久化数据时:$em->persist($form->getData()); 我得到了错误:
"The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces".
有什么建议吗?
为了更清楚,我在下面添加了一些代码:
首先,我为多对多关系注释了文档中所说的实体:
/**
* @ORM\ManyToMany(targetEntity="\User\Entity\Client", mappedBy="reportSettings")
*/
private $client;
public function __construct() {
$this->client = new ArrayCollection();
}
和
/**
* @ORM\ManyToMany(targetEntity="\Statistics\Entity\ReportSettings", inversedBy="client")
* @ORM\JoinTable(name="report_client_settings",
* joinColumns={@ORM\JoinColumn(name="client_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="report_setting_id", referencedColumnName="id")})
*/
private $reportSettings;
public function __construct() {
$this->reportSettings = new ArrayCollection();
}
在控制器中
$form = new UpdateReportSettingsForm();
$form->bind($reportSettings);
$request = new Request();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$em->persist($data); // here I got the error - The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces
$em->flush();
}
我也以 DoctrineModule\Form\Element\ObjectMultiCheckbox 的形式使用。
一个简单的var_dump($data) - 返回一个持久集合。
【问题讨论】:
-
如果你能把代码给我们看,给你一个合理的答案会更容易。
-
我添加了一些代码。如果还不够,请告诉我,我会添加更多。
-
发布您的完整实体,错误只是说明您的名称空间没有提到包含的类,这有点含糊。
标签: orm doctrine-orm zend-framework2