src/Controller/Applicant/SuggestionController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Applicant;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use App\Entity\Suggestion;
  9. use App\Form\SuggestionType;
  10. /**
  11.  *
  12.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  13.  */
  14. class SuggestionController extends AbstractController
  15. {
  16.     /**
  17.      *
  18.      * @Route("/applicant/suggestion", name="applicant_suggestion")
  19.      */
  20.     public function suggestion(Request $requestEntityManagerInterface $em): Response
  21.     {
  22.         $suggestion = new Suggestion();
  23.         $user $this->getUser();
  24.         $suggestion->setUser($user);
  25.         $form $this->createForm(SuggestionType::class, $suggestion);
  26.         $form->handleRequest($request);
  27.         if ($form->isSubmitted() && $form->isValid()) {
  28.             $em->persist($suggestion);
  29.             $em->flush();
  30.             $this->addFlash('notice''操作成功');
  31.             return $this->redirectToRoute('applicant');
  32.         }
  33.         return $this->render('applicant/suggestion.html.twig', [
  34.             'title' => '问题与建议',
  35.             'form' => $form->createView()
  36.         ]);
  37.     }
  38. }