Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. class DefaultController extends Controller
  6. {
  7.     /**
  8.      * @Route("/delete-client/{id}")
  9.      */
  10.     public function deleteAction3($id)
  11.     {
  12.         $em = $this->getDoctrine()->getManager();
  13.         $client = $em->getRepository(Client::class)->find($id);
  14.        
  15.         if (!$client) {
  16.             throw $this->createNotFoundException(
  17.                 'There are no users with the following id: ' . $id
  18.             );
  19.         }
  20.  
  21.         $em->remove($client);
  22.        
  23.         $user = $em->getRepository(User::class)->findOneBy(['client' => $id]);
  24.         if ($user) {
  25.             $em->remove($user);
  26.         }
  27.  
  28.         $em->flush();
  29.  
  30.         return $this->redirect('/show-client');
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement