src/Controller/TicketController.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Ticket;
  4. use App\Form\Type\TicketType;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class TicketController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/Ticketupload", name="ticketupload")
  12.      */
  13.     public function new(Request $request)
  14.     {
  15.         $item = new Ticket();
  16.         $form $this->createForm(TicketType::class, $item);
  17.         $form->handleRequest($request);
  18.         if ($form->isSubmitted() && $form->isValid()) {
  19.             $item $form->getData();
  20.             $ticketFile $form->get('ticketFilename')->getData();
  21.             if ($ticketFile) {
  22.                 $originalFilename pathinfo($ticketFile->getClientOriginalName(), PATHINFO_FILENAME);
  23.                 $safeFilename transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()'$originalFilename);
  24.                 $newFilename $safeFilename.'-'.uniqid().'.'.$ticketFile->guessExtension();
  25.                 try {
  26.                     $ticketFile->move(
  27.                         $this->getParameter('brochures_directory'),
  28.                         $newFilename
  29.                     );
  30.                 } catch (FileException $e) {
  31.                     // ... handle exception if something happens during file upload
  32.                 }
  33.                 $item->setTicketFilename($newFilename);
  34.             }
  35.             $item->setIP($_SERVER['REMOTE_ADDR']);
  36.             $item->setDate(new \DateTime("now"));
  37.             $entityManager $this->getDoctrine()->getManager();
  38.             $entityManager->persist($item);
  39.             $entityManager->flush();
  40.             return $this->redirectToRoute('success');
  41.         }
  42.         return $this->render('default/ticket.html.twig', [
  43.             'form' => $form->createView(),
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/", name="index")
  48.      */
  49.     public function index()
  50.     {
  51.         return $this->render('default/index.html.twig', []);
  52.     }
  53.     /**
  54.      * @Route("/Danke", name="success")
  55.      */
  56.     public function success()
  57.     {
  58.         return $this->render('default/success.html.twig', []);
  59.     }
  60. }