src/Controller/Front/Modules/MenuController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Modules;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use App\Entity\Category;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  11. class MenuController extends \App\Controller\Front\FrontController
  12. {
  13. public function main(Request $request, EntityManagerInterface $em, \Symfony\Component\HttpKernel\KernelInterface $kernel, \App\Manager\CustomerManager $customerMgr)
  14. {
  15. $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
  16. // $cache->deleteItem('main-menu-'.$request->getLocale());
  17. $key = $kernel->getEnvironment().'-main-menu-'.$request->getLocale();
  18. if($customerMgr->isExpert()) {
  19. $key .= '-expert';
  20. }
  21. $menuItem = $cache->getItem($key);
  22. if (!$menuItem->isHit()) {
  23. $categories = $em->getRepository(Category::class)->getRoots(5);
  24. $html = $this->renderView('front/modules/menu/cache.html.twig', [
  25. 'categories' => $categories
  26. ]);
  27. $menuItem->set($html);
  28. $cache->save($menuItem);
  29. }
  30. $menu = $menuItem->get();
  31. return $this->render('front/modules/menu/main.html.twig', [
  32. 'cache' => $menu
  33. ]);
  34. }
  35. }