Mam taki problem. Stworzyłem formularz przez CRUD. Wygenerował mi on taki formularz dodawania nowego miasta
<h1>City creation</h1> <form action="{{ path('city_create') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <p> <button type="submit">Create</button> </p> </form> <ul class="record_actions"> <li> <a href="{{ path('city') }}"> Back to the list </a> </li> </ul>
i wszystko ładnie działa, dodaje miasto do bazy. ale gdy zamienię ten formularz na taki, to już nie dodaje mi do bazy. Nie wyświetla też żadnego błędu.
<h1>City creation</h1> <form action="{{ path('city_create') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form.name) }} <p> <button type="submit">Create</button> </p> </form> <ul class="record_actions"> <li> <a href="{{ path('city') }}"> Back to the list </a> </li> </ul>
z tego co ustaliłem to formularz chyba nie przechodzi walidacji w kontrolerze. Co zrobiłem źle.
o to akcja odpowiedzialna za dodanie nowego miasta
public function createAction(Request $request) { $entity = new City(); $form = $this->createForm(new CityType(), $entity); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); } 'entity' => $entity, 'form' => $form->createView(), )); }