src/Controller/RefrenceController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Refrence;
  4. use App\Form\RefrenceType;
  5. use App\Repository\RefrenceRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/refrence")
  12.  */
  13. class RefrenceController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/list", name="app_refrence_list", methods={"GET"})
  17.      */
  18.     public function list(RefrenceRepository $refrenceRepository): Response
  19.     {
  20.         return $this->render('refrence/list.html.twig', [
  21.             'refrences' => $refrenceRepository->findByRefLetter('Please upload'),
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route("/new", name="app_refrence_new", methods={"GET", "POST"})
  26.      */
  27.     public function new(Request $requestRefrenceRepository $refrenceRepository): Response
  28.     {
  29.         $refrence = new Refrence();
  30.         $form $this->createForm(RefrenceType::class, $refrence);
  31.         $form->handleRequest($request);
  32.         if ($form->isSubmitted() && $form->isValid()) {
  33.             //get Ref Letter File name
  34.             $appFile $form->get('refLet')->getData();
  35.             print $appFile;
  36.             if ($appFile){
  37.                 
  38.                 $newAFilename md5(uniqid()).'.'.$appFile->guessClientExtension();
  39.                 // Move the file to the directory where brochures are stored
  40.                 try {
  41.                     $appFile->move(
  42.                         $this->getParameter('brochures_directory'),
  43.                         $newAFilename
  44.                     );
  45.                 } catch (FileException $e) {
  46.                     // ... handle exception if something happens during file upload
  47.                 }
  48.             }
  49.             $refrence->setRefLetter($newAFilename);
  50.             $refrenceRepository->add($refrencetrue);
  51.             return $this->redirectToRoute('app_refrence_sucess', [], Response::HTTP_SEE_OTHER);
  52.         }
  53.         return $this->renderForm('refrence/new.html.twig', [
  54.             'refrence' => $refrence,
  55.             'form' => $form,
  56.         ]);
  57.     }
  58. /**
  59.      * @Route("/sucess", name="app_refrence_sucess", methods={"GET"})
  60.      */
  61.     public function showsucess(): Response
  62.     {
  63.         return $this->render('refrence/success.html.twig');
  64.     }
  65.     /**
  66.      * @Route("/{id}", name="app_refrence_show", methods={"GET"})
  67.      */
  68.     public function show(Refrence $refrence): Response
  69.     {
  70.         return $this->render('refrence/show.html.twig', [
  71.             'refrence' => $refrence,
  72.         ]);
  73.     }
  74.     /**
  75.      * @Route("/{id}/edit", name="app_refrence_edit", methods={"GET", "POST"})
  76.      */
  77.     public function edit(Request $requestRefrence $refrenceRefrenceRepository $refrenceRepository): Response
  78.     {
  79.         $form $this->createForm(RefrenceType::class, $refrence);
  80.         $form->handleRequest($request);
  81.         if ($form->isSubmitted() && $form->isValid()) {
  82. //get Ref Letter File name
  83. $appFile $form->get('RefLet')->getData();
  84. print $appFile;
  85. if ($appFile){
  86.     
  87.     $newAFilename md5(uniqid()).'.'.$appFile->guessClientExtension();
  88.     // Move the file to the directory where brochures are stored
  89.     try {
  90.         $appFile->move(
  91.             $this->getParameter('brochures_directory'),
  92.             $newAFilename
  93.         );
  94.     } catch (FileException $e) {
  95.         // ... handle exception if something happens during file upload
  96.     }
  97. }
  98. $refrence->setRefLetter($newAFilename);
  99.             $refrenceRepository->add($refrencetrue);
  100.             return $this->redirectToRoute('app_refrence_sucess', [], Response::HTTP_SEE_OTHER);
  101.         }
  102.         return $this->renderForm('refrence/edit.html.twig', [
  103.             'refrence' => $refrence,
  104.             'form' => $form,
  105.         ]);
  106.     }
  107.     /**
  108.      * @Route("/{id}", name="app_refrence_delete", methods={"POST"})
  109.      */
  110.  /*   public function delete(Request $request, Refrence $refrence, RefrenceRepository $refrenceRepository): Response
  111.     {
  112.         if ($this->isCsrfTokenValid('delete'.$refrence->getId(), $request->request->get('_token'))) {
  113.             $refrenceRepository->remove($refrence, true);
  114.         }
  115.         return $this->redirectToRoute('app_refrence_list', [], Response::HTTP_SEE_OTHER);
  116.     }*/
  117. }