2013-02-13 2 views
0

두 개의 엔티티 양식이 '주문'및 '주소'로 있습니다. 주소 양식을 주문 양식에 삽입하고 싶습니다. 두 엔티티 모두 사용자 열에 의해 관계가 있습니다.하나의 양식을 다른 symfony2에 포함하십시오

주소 엔티티

class Address 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", length=128) 
    */ 
    protected $type;  

    /** 
    * @ORM\ManyToOne(targetEntity="Root\UserBundle\Entity\User", inversedBy="address") 
    * @ORM\JoinColumn(name="user", referencedColumnName="id") 
    * @ORM\ManyToOne(targetEntity="Orders", inversedBy="address") 
    * @ORM\JoinColumn(name="user", referencedColumnName="user") 
    */  
    protected $user;  

주문 엔티티

class Orders 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", length=128) 
    */ 
    protected $status;  

    /** 
    * @ORM\ManyToOne(targetEntity="Root\UserBundle\Entity\User", inversedBy="orders") 
    * @ORM\JoinColumn(name="user", referencedColumnName="id") 
    * @ORM\OneToMany(targetEntity="Address", mappedBy="orders") 
    * @ORM\JoinColumn(name="user", referencedColumnName="user") 
    */  
    protected $user;  

주문 양식

namespace Root\ContestBundle\Form\Front; 

use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 
use Symfony\Component\OptionsResolver\OptionsResolverInterface; 
use Root\ContestBundle\Entity\Address; 
use Root\ContestBundle\Form\Front\AddressType; 
class OrdersType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('address', 'collection', array('type' => new AddressType())); 
     $builder 
     ->add('termsAccepted'); 

    } 

그러나 나는 getti 오전 오류가 아래와 같습니다.

An exception has been thrown during the rendering of a template ("Neither property "address" nor method "getAddress()" nor method "isAddress()" exists in class "Root\ContestBundle\Entity\Orders"") 

그래서 내 코드에서 어떤 실수를 했습니까? 도와주세요

답변

3

어쩌면 너무 늦었지만 제 대답은 여기에 있습니다. 며칠 전에 심포니를 발견 했으므로 전문가가 아닙니다. 내게 어색한 것처럼 보이는 것이 거의 없습니다. ADRESS 엔티티에

, 난 당신이 그렇게해야한다고 생각 :

주문 엔티티에
/** @ORM\OneToMany(targetEntity="Order", mappedBy="adress") */ 
protected $orders; 

public function addOrder(Order $order){ 
    $this->orders[] = $order; 
} 

public function removeOrder(Order $order){ 
    $this->orders->removeElement($order); 
} 

public function getOrders(){ 
    return $this->orders; 
} 

, 나는 당신이이 sould 생각 :

/** 
* @ORM\ManyToOne(targetEntity="Address", inversedBy="orders") 
* @ORM\JoinColumn(name="idAdress", referencedColumnName="id") 
*/  
protected $adress; 

public function setAdress($adress){ 
    $this->adress = $adress; 
} 

public function getAdress(){ 
    return $this->adress; 
} 

그리고 OrderType 당신에 마지막으로, 당신이해야한다고 생각 있습니다 :

public function buildForm(FormBuilderInterface $builder, array $options){ 
    $builder->add('adress',new AdressType()); 
} 

희망이 도움이 될 것입니다.

관련 문제