2013-11-22 9 views
0

직원 등록 시스템이 있다고 가정 해 보겠습니다. 우리는 네 개의 기관이있다 : 직원, 로그인, 전화가 이메일 은 한 직원이 많은 로그인, S, 많은 전화와 ManyEmails이Symfony 업데이트 관련 엔티티

내가 만든했다 LoginType :

public function buildForm(FormBuilderInterface $builder, array $options) { 
    $builder 
      ->add('username') 
      ->add('password'); 
} 

그런 전화 유형 :

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

이메일 유형

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

그리고 마지막으로 직원 유형, 어떤 관계 togheder 모두 플러스 몇 가지 추가 필드 : ORM에서

public function buildForm(FormBuilderInterface $builder, array $options) { 
    $builder 
      ->add('firstname') 
      ->add('middleNames') 
      ->add('lastname') 
      ->add('dateofbirth', 'date', array(
       'widget' => 'single_text', 
       'read_only' => true 
      )) 
      ->add('address') 
      ->add('idcode') 
      ->add('position') 
      ->add('phone', new EmployeePhoneType(), array('data_class' => null)) 
      ->add('email', new EmployeeEmailType(), array('data_class' => null)) 
      ->add('login', new LoginType(), array('data_class' => null)) 
      ->add('save', 'submit'); 
} 

는 모든 엔티티는 관계

class Employee { 
    /* ...Other fileds not shown here...*/ 

    /** 
    * @var Doctrine\Common\Collections\ArrayCollection $login 
    * @ORM\OneToMany(targetEntity="Crm\AuthBundle\Entity\Login", mappedBy="employee", cascade={"persist"}) 
    */ 
    protected $login; 
    /** 
    * @var Doctrine\Common\Collections\ArrayCollection $phone 
    * @ORM\OneToMany(targetEntity="Crm\AdminBundle\Entity\EmployeePhone", mappedBy="employee", cascade={"persist"}) 
    */ 
    protected $phone; 

    /** 
    * @var Doctrine\Common\Collections\ArrayCollection $email 
    * @ORM\OneToMany(targetEntity="Crm\AdminBundle\Entity\EmployeeEmail", mappedBy="employee", cascade={"persist"}) 
    */ 
    protected $email; 

    } 


class EmployeePhone{ 
    /** 
    * @ORM\ManyToOne(targetEntity="Crm\AdminBundle\Entity\Employee", inversedBy="phone", cascade={"persist"}) 
    * @ORM\JoinColumn(name="employee_id", referencedColumnName="id", nullable=false) 
    */ 
    private $employee; 
} 

class EmployeeEmail{ 
    /** 
    * @ORM\ManyToOne(targetEntity="Crm\AdminBundle\Entity\Employee", inversedBy="email", cascade={"persist"}) 
    * @ORM\JoinColumn(name="employee_id", referencedColumnName="id", nullable=false) 
    */ 
    private $employee; 
} 
class Login{ 
    /** 
    * @ORM\ManyToOne(targetEntity="Crm\AdminBundle\Entity\Employee", inversedBy="login", cascade={"persist"}) 
    * @ORM\JoinColumn(name="employee_id", referencedColumnName="id", nullable=false) 
    */ 
    protected $employee; 
} 

이 지금은 updtade 작업을 할 때 컨트롤러의 첫 번째 부하 직원 개체 :

$employee = $this->getDoctrine()->getRepository('AdminBundle:Employee') 
      ->find($empId); 

양식을 작성하고 양식을 사용하여 $ employee를 묶습니다.

$form = $this->createForm(new EmployeeType(), $employee, array(
      'action' => $this->generateUrl('employee_save') 
     )); 

문제 $ 직원 개체 자체가 올바르게로드되어 양식 필드에 표시되지만 모든 관련 개체는 개체 (Doctrine \ ORM \ PersistentCollection)로 표시되고 데이터는 검색되지 않습니다. PersistentCollections에 대해 initialize()를 수행하더라도 데이터는 coll atribute 아래에 표시되지만 양식에는 표시되지 않습니다.

업데이트 작업을 올바르게 수행하는 방법은 무엇입니까?

+0

dataclass를 올바른 유형으로 설정 했습니까? –

답변

0

예를 수집 유형 필드 내가 응용 프로그램 실현이 경우되어 최선의 선택을했지만 것 때문에/Email/LoginEmployeePhone 사이에 일대 다 관계에 대한 collection field-type을 찾고 실제로 전화 번호와 전자 메일 필드가 고정 된 번호가 필요합니다. 그런 다음 별도 엔티티를 제거하고 고정 엔트리 수를 기본 엔티티에 저장했습니다. 또한 data_class를 수정하여이를 수정하십시오.

관련 문제