public function buildForm(FormBuilderInterface $builder, array $options)
{
$selects = [
'class' => 'AppBundle\Entity\Location',
'choice_label' => 'name',
'choice_value' => 'alias',
'data'=>'AppBundle\Entity\Location'
];
$builder
->add('tripTitle')
->add('tripFrom', EntityType::class, $selects)
->add('tripTo', EntityType::class, $selects);
}
/**
* Displays a form to edit an existing Trip entity.
*
* @Route("/{id}/edit", name="trip_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Trip $trip)
{
$deleteForm = $this->createDeleteForm($trip);
$editForm = $this->createForm('AppBundle\Form\TripType', $trip);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($trip);
$em->flush();
return $this->redirectToRoute('trip_edit', array('id' => $trip->getId()));
}
return $this->render('@App/Trip/edit.html.twig', array(
'trip' => $trip,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// // настройки для отображения селектов
$selects = [
'class' => 'AppBundle\Entity\Location',
'choice_label' => 'name',
'choice_value' => 'alias'
];
$builder
->add('tripTitle')
->add('tripFrom', EntityType::class, $selects)
->add('tripTo', EntityType::class, $selects);
}
$form = $this->createFormBuilder($book)
->add('sessid', 'hidden', array('attr' => array('value' => $request->cookies->get('PHPSESSID'))))
->add('date', DateTimeType::class, array('widget' => 'single_text'))
->add('fromBook', EntityType::class, $selectsSetting)
->getForm();
public function findAction(Request $request)
{
$book = new Book();
//шаг первый - запоняем начальные поля
$form = $this->createFormBuilder($book)
->add('sessid', 'hidden', array('attr' => array('value' => $request->cookies->get('PHPSESSID'))))
->add('date', DateTimeType::class, array('widget' => 'single_text'))
->add('fromBook', ChoiceType::class)
->add('toBook', ChoiceType::class)
->add('returnDate', DateTimeType::class, array('widget' => 'single_text'))
->add('returnFrom', ChoiceType::class)
->add('returnTo', ChoiceType::class)
->add('people')
->add('isReturn', CheckboxType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
return $this->redirectToRoute('app_book_getcars', array(
'form' => $form
));
}
}
создал несколько класс формы
и в коетроллере главной страницы могу вызвать формбилдер
вопрос в том, не правильней ли формбилдер вызывать в BookController
а уже из HomeController вызывать метод из BookController ?