안녕하세요이 Symfony2 함께 일하고 나는 이러한 관계가 있습니다symfony2 관계 교리
테이블 의사 :
/**
* @ORM\OneToMany(targetEntity="Cita", mappedBy="medico")
*/
protected $citas;
테이블 citas :
다음/**
* @ORM\ManyToOne(targetEntity="Medico", inversedBy="citas")
*/
protected $medico;
이 코드가 약속을 의사가 만들어집니다.
$em = $this->get('doctrine')->getEntityManager();
$cita = new Cita();
$empleado = $this->get('security.context')->getToken()->getUser();
$cita->setEmpleado($empleado);
$cliente = $this->getDoctrine()->getRepository('miomioBundle:Usuario')->find($this->getRequest()->query->get('cliente'));
$cita->setFechacita(new \DateTime($this->getRequest()->query->get('fecha')));
$cita->setCliente($cliente);//asociacion de cita a usuario.
$cita->setFechaoper(new \DateTime('now'));
$medico = $this->getDoctrine()->getRepository('miomioBundle:Medico')->find($this->getRequest()->query->get('medico'));
$cita->setMedico($medico);
$em->persist($cita);
$em->persist($cliente);
$em->persist($empleado);
$em->flush();
및
는 의사의 약속을 얻으려고 노력 :public function pintarAction($id)
{
$return_arr = array();
$medico = $this->getDoctrine()->getRepository('miomioBundle:Medico')->find($id);
$citas = $medico->getCitas();
foreach($citas as $cita){
return new Response('entra');
$array['id'] = (string)$cita->getId();
$array['title'] = $cita->getCliente()->getNombre() . ' '. $cita->getCliente()->getApellido1();
$array['empleado'] = $cita->getEmpleado()->getUsername();
if ($cita->getInforme()){
$array['informe'] = $cita->getInforme()->getId();
$array['className'] = 'informe';
}
else{
$array['informe'] = 'NO';
$array['className'] = '';
}
$array['fecha'] = $cita->getFechaoper()->format('d-m-Y H:i:s');
$array['start'] = $cita->getFechacita()->format('Y-m-d H:i:s');
$array['allDay'] = false;
array_push($return_arr,$array);
}
return new Response(json_encode($return_arr), 200, array('Content-Type', 'text/json'));
}
변수 $ 의사가 확인입니다. 변수 $ citas는 비어 있습니다. 왜?
누군가 내가 잘못하고 있다는 것을 알고 있습니까? 인사와 감사.
1.'return' 절로 인해'pintarAction' 메소드가'foreach' 루프에 입력하자마자 종료됩니다. 2. db가 선택된 medico에 대한 실제 데이터를 가지고 있는지 확인하십시오. 3. 화 내지 마세요, [FOSRestBundle] (https://github.com/FriendsOfSymfony/FOSRestBundle)을 사용하십시오! – moonwave99