public function showAction($id)
{
$products = $this->getDoctrine()->getRepository('AppBundle:Product')->find($id);
if (!$products) {
throw $this->createNotFoundException('Товар не найден.');
}
$form = $this->createFormBuilder($products)
->add('category', TextType::class)
->add('title', TextType::class)
->add('description', TextType::class)
->add('price', TextType::class)
->add('active', CheckboxType::class)
->add('Submit', SubmitType::class)
->getForm();
// $form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$products = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->flush();
// return $this->redirectToRoute('show/id');
// return new Response(
// '<html><body>Наименование:' . $products->getTitle() . ' </body></html>');
}
return $this->render('@App/Product/edit.html.twig', ['form' => $form->createView()]);
}
$em = $this->getDoctrine()->getManager();
$product = $em->getRepository('AppBundle:Product')->find($productId);
$form = $this->createForm(ProductType::class, $product);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->flush();
return $this->redirectToRoute('home');
}
return $this->render('@App/Product/edit.html.twig', [
'form' => $form->createView()
]);
/**
*
*@Route('/product/{id}/edit')
*/
public function edit(Product $product, Request $request)
{
}
Спасибо большое. А так можно было? ))
/**
* @Route ("/show/{id}", name="product_item",requirements={"id":"[0-9]+"});
*/
public function showAction(Product $id, Request $request)
{
$products = $this->getDoctrine()->getRepository('AppBundle:Product')->find($id);
if (!$products) {
throw $this->createNotFoundException('Товар не найден.');
}
$form = $this->createForm(ProductType::class, $products);
$form->add('Submit', SubmitType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$products = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->flush();
// return $this->redirectToRoute('product_item', $id);
return $this->render('@App/Product/edit.html.twig', ['form' => $form->createView()]);
}
}