Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/article/delete/{id}", name="article_delete")
- * @param $id
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function delete($id, Request $request)
- {
- $article = $this->getDoctrine()->getRepository(Article::class)->find($id);
- if($article === null){
- return $this->redirectToRoute("blog_index");
- }
- $currentUser = $this->getUser();
- if(!$currentUser->isAuthor($article) && !$currentUser->isAdmin())
- {
- return $this->redirectToRoute("blog_index");
- }
- $form = $this->createForm(ArticleType::class, $article);
- $form->handleRequest($request);
- if($form->isSubmitted() && $form->isValid())
- {
- $em = $this->getDoctrine()->getManager();
- $em->remove($article);
- $em->flush();
- return $this->redirectToRoute('blog_index');
- }
- return $this->render('article/delete.html.twig', array('article' => $article, 'form' => $form->createView()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement