我有一个表单,您可以在其中编辑对象“一个”的属性。该对象与另一个对象“many”具有一对多的关系。我希望用户能够从表单中选择将“许多”对象分配给“一个”。我不知道该怎么做!
现在:
\Entity\One.php
class One
{
...
/*
* @ORM\ManyToOne(targetEntity="many", inversedBy="one")
* @ORM\JoinColumn(name="manyId", referencedColumnName="id")
*/
protected $manyId;
...
}
\控制器\OneController.php
class OneController extends Controller
{
...
public function editAction($oneId, Request $request)
{
if ($oneId) {
$one = $this->getDoctrine()
->getRepository('One')
->find($oneId);
} else {
$one = new One();
}
$em = $this->getDoctrine()->getEntityManager();
$manyEntity = 'Bundle\Entity\Many';
$manyList = new EntityChoiceList($em, $manyEntity);
$form = $this->createFormBuilder($one)
->add('many', 'choice', array('choice_list' => $manyList))
->getForm();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$entityManager = $this->getDoctrine()->getEntityManager();
$entityManager->persist($one);
}
}
}
...
}
这会导致错误消息““标量”类型的预期参数,“Proxies\BundleEntityManyProxy”给定”。
谢谢你的帮助!