Answer the question
In order to leave comments, you need to log in
Can you please explain how updating a record in a Symfony/Doctrine database works?
I am learning Symfony-3. Generated entities, created forms, generated CRUD... For example, we took the vendor table , which consists of 3 simple fields: id, title, email.
The standard code from the CRUD generator, which is not completely clear to me:
/**
* Displays a form to edit an existing vendor entity.
*
* @Route("/{id}/edit", name="vendor_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Vendor $vendor)
{
$deleteForm = $this->createDeleteForm($vendor);
$editForm = $this->createForm('AppBundle\Form\VendorType', $vendor);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('vendor_edit', array('id' => $vendor->getId()));
}
return $this->render('vendor/edit.html.twig', array(
'vendor' => $vendor,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
public function editAction(Request $request, Vendor $vendor)
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
Answer the question
In order to leave comments, you need to log in
If we had two forms passed at once, for example, Vendor and User, would the User object also appear and would it be automatically assigned to the $user variable? Usually, I pulled out the necessary data directly from the $request variable and assigned it "by hand" where I needed (although I certainly like this option too).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question