2 pièce(s) jointe(s)
Symfony2 -Update -Integrity constraint violation
Bonjour a tous,
je suis en train d'implementer update action dans mon controlleur
Pièce jointe 151030
La vue Twig:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <h1>Modify Menu</h1>
<form action="" method="post" {{ form_enctype(form) }}>
<ul>
<li>
<label for="name">Title:</label>
{{form(form.title)}}
</li>
<li>
<label for="Position">Position:</label>
{{form(form.position)}}
</li>
<input type="hidden" name="name" value="submit">
{{form_widget(form._token)}}
<p>
<button type="submit" class="action">Submit</button>
<button type="reset" class="right">Reset</button>
</p>
</ul>
</form> |
Controlleur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public function editAction($id, Request $request) {
$em = $this->getDoctrine()->getManager();
$menu = $em->getRepository('MyAppEspritBundle:Menu')->find($id);
if (!$menu) {
throw $this->createNotFoundException(
'No menu found for id ' . $id
);
}
$form = $this->createFormBuilder($menu)
->add('title', 'text')
->add('position', 'text')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$em->flush();
return new Response('menu updated successfully');
}
$build['form'] = $form->createView();
return $this->render('MyAppEspritBundle:Menu:edit.html.twig', $build);
} |
Pièce jointe 151031
merci d 'avance[/CENTER]