직원 등록 시스템이 있다고 가정 해 보겠습니다. 우리는 네 개의 기관이있다 : 직원, 로그인, 전화가 이메일 은 한 직원이 많은 로그인, 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 아래에 표시되지만 양식에는 표시되지 않습니다.
업데이트 작업을 올바르게 수행하는 방법은 무엇입니까?
dataclass를 올바른 유형으로 설정 했습니까? –