2012-04-21 6 views
2

オブジェクト "one"の属性を編集できるフォームがあります。このオブジェクトは、他のオブジェクト「多」と1対多の関係を持ちます。フォームから「1」に「多くの」オブジェクトを割り当てるようにユーザーが選択できるようにしたい。私はそれを行う方法を理解することはできません!今Symfony 2のオブジェクトリストから選択する方法オブジェクトフォームを編集する

\エンティティ\ 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 "が指定されました。

ありがとうございました!

答えて

関連する問題