src/Controller/Frontend/TFeedbackController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Controller\Base\BaseController;
  4. use App\Entity\Feedback;
  5. use App\Form\FeedbackType;
  6. use App\Repository\FeedbackRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class TFeedbackController extends BaseController
  13. {
  14.     /**
  15.      * @Route("/t/feedback", name="t_feedback")
  16.      */
  17.     public function index(): Response
  18.     {
  19.         return $this->render('t_feedback/index.html.twig', [
  20.             'controller_name' => 'TFeedbackController',
  21.         ]);
  22.     }
  23.     /**
  24.      * @Route("tfeedback/request/{id}", defaults={"id"=null}, name="tfeedback_form", methods={"GET","POST"})
  25.      */
  26.     public function form(?string $id nullRequest $requestFeedbackRepository $feedbackRepository)
  27.     {
  28.         // print_r('ya');exit;
  29.         if ($id) {
  30.             $feedback $feedbackRepository->find($id);
  31.         } else {
  32.             $feedback = new Feedback();
  33.         }
  34.         if (!$feedback) {
  35.             throw new NotFoundHttpException();
  36.         }
  37.         $form $this->createForm(FeedbackType::class, $feedback, ['action' => $this->generateUrl('tfeedback_form', ['id' => $feedback->getId()])]);
  38.         $form->handleRequest($request);
  39.         if ($form->isSubmitted() && $form->isValid()) {
  40.             $user $form->getData();
  41.             $user->setRating($request->request->get('star'));
  42.             $user->setCreatedAt(new \DateTime());
  43.             $entityManager $this->getDoctrine()->getManager();
  44.             $entityManager->persist($user);
  45.             $entityManager->flush();
  46.             $this->addFlash('notice''Berhasil dikirim');
  47.             return $this->redirectToRoute('homepage');
  48.             // return $this->redirect($request->server->get('HTTP_REFERER'));
  49.         }
  50.         return $this->render('/frontend/t_feedback/form.html.twig', [
  51.             'form' => $form->createView(),
  52.             'header_kategori' => $this->getHeaderKategori(),
  53.         ]);
  54.     }
  55. }