如何从Symfony 2编辑对象窗体中的对象列表中进行选择
我有一个表单,您可以在其中编辑对象“一”的属性。此对象与另一个对象“多”具有一对多关系。我希望用户能够从表单中选择将“多”对象分配给“一”。我不知道该怎么做 现在: \Entity\One.php如何从Symfony 2编辑对象窗体中的对象列表中进行选择,symfony,symfony-forms,Symfony,Symfony Forms,我有一个表单,您可以在其中编辑对象“一”的属性。此对象与另一个对象“多”具有一对多关系。我希望用户能够从表单中选择将“多”对象分配给“一”。我不知道该怎么做 现在: \Entity\One.php class One { ... /* * @ORM\ManyToOne(targetEntity="many", inversedBy="one") * @ORM\JoinColumn(name="manyId", referencedColumnName="id") */
class One
{
...
/*
* @ORM\ManyToOne(targetEntity="many", inversedBy="one")
* @ORM\JoinColumn(name="manyId", referencedColumnName="id")
*/
protected $manyId;
...
}
\Controller\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“给定”
谢谢你的帮助 解决了!我应该写
->add('many','entity',array('class'=>'BundleMany'))
看