Symfony 'Collection'양식 필드 유형을 사용하고 Doctrine을 사용하여 원하는 LogEvent 엔티티를 찾고이를 Collection으로 전달하십시오.
예 : http://symfony.com/doc/current/cookbook/form/form_collections.html
참조 :
:
class LogEventType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('text');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'My\Bundle\Entity\LogEvent',
));
}
public function getName()
{
return 'log_event';
}
}
그런 다음 LOGEVENT 엔티티의 컬렉션을 보유하고 양식 유형을 : http://symfony.com/doc/current/reference/forms/types/collection.html
그래서 먼저 당신은 당신의 LOGEVENT 양식 유형을 만들 것
class MultiLogEventType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'logEvents', 'collection', array('type' => new LogEventType())
);
}
public function getName()
{
return 'multi_log_event';
}
}
T 당신의 컨트롤러에서 암탉, 그것은 당신의 로그 이벤트를 양식을 작성하고 전달합니다
public function editAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$editForm = $this->createForm(new MultiLogEventType());
$editForm->handleRequest($request);
if ($editForm->isValid())
{
foreach ($logEvents as $logEvent) {
// perform any logic you need to here
// (ex: removing the log event; $em->remove($logEvent);)
}
$em->flush();
}
return $this->redirect($this->generateUrl('log_event_edit'));
}
나 ': 당신의 편집 작업 로그 이벤트를 통해 루프 당신이해야 할 무엇이든 할 수있는 그런
을 d는 이것에 대한 답을 정말 갖고 싶어! :) 해결 방법은 모든'LogEvent'를 마스터 엔티티에 첨부하는 것일 수 있다고 생각합니다. 그런 다음 해당 마스터 엔티티의 양식을 작성하고'LogEvent' 양식을 그 안에 삽입하십시오. – paulgv
로그 이벤트의 배열을 만들고이를 'collection'요소가있는 양식으로 전달하십시오. http://symfony.com/doc/current/cookbook/form/form_collections.html – Cerad