datatableResponse = $datatableResponse; $this->Datatable = $datatableFactory->create(Datatable::class); $this->Manager = $Manager; } /** * @Route("/", name="_index", methods={"GET"}) */ public function index(Request $request): Response { $this->Datatable->buildDatatable(); return $this->render('/index.html.twig', [ 'datatable' => $this->Datatable ]); } /** * @Route("/refresh", name="_refresh", methods={"POST"}) * * @return JsonResponse */ public function refresh(): JsonResponse { try { $this->Datatable->buildDatatable(); $this->datatableResponse->setDatatable($this->Datatable); $this->datatableResponse->getDatatableQueryBuilder(); return $this->datatableResponse->getResponse(); } catch (\Exception $exception) { return $this->json(['error' => $exception->getMessage()]); } } /** * @Route("/new", name="_new", methods={"GET","POST"}) */ public function new(Request $request): Response { $ = new (); $form = $this->createForm(::class, $); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->Manager->save($); $this->addFlash('success', 'label.save_successfully'); return $this->redirectToRoute('_index'); } return $this->renderForm('/new.html.twig', [ '' => $, 'form' => $form, ]); } /** * @Route("/{}", name="_show", methods={"GET"}) */ public function show( $): Response { return $this->render('/show.html.twig', [ '' => $, ]); } /** * @Route("/{}/edit", name="_edit", methods={"GET","POST"}) */ public function edit(Request $request, $): Response { $form = $this->createForm(::class, $); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->getDoctrine()->getManager()->flush(); $this->addFlash('success', 'label.save_successfully'); return $this->redirectToRoute('_index'); } return $this->renderForm('/edit.html.twig', [ '' => $, 'form' => $form, ]); } /** * @Route("/{}/delete", name="_delete", methods={"POST"}) */ public function delete(Request $request, $): Response { if ($this->isCsrfTokenValid('delete'.$->get(), $request->request->get('_token'))) { $this->Manager->remove($); $this->addFlash('success', 'label.message_delete'); } return $this->redirectToRoute('_index'); } /** * @Route("/{}/delete", name="_delete_get", methods={"GET"}) */ public function deleteGet(Request $request, $): Response { $this->Manager->remove($); $this->addFlash('success', 'label.message_delete'); return $this->redirectToRoute('_index'); } }