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

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.     
  14.     public function main(Request $requestEntityManagerInterface $em, \Symfony\Component\HttpKernel\KernelInterface $kernel, \App\Manager\CustomerManager $customerMgr)
  15.     {
  16.         $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
  17. //        $cache->deleteItem('main-menu-'.$request->getLocale());
  18.         $key $kernel->getEnvironment().'-main-menu-'.$request->getLocale();
  19.         if($customerMgr->isExpert()) {
  20.             $key .= '-expert';
  21.         }
  22.         $menuItem $cache->getItem($key);
  23.         if (!$menuItem->isHit()) {
  24.             $categories $em->getRepository(Category::class)->getRoots(5);
  25.             $html $this->renderView('front/modules/menu/cache.html.twig', [
  26.                 'categories' => $categories
  27.             ]);
  28.             $menuItem->set($html);
  29.             $cache->save($menuItem);
  30.         }
  31.         $menu $menuItem->get();
  32.         return $this->render('front/modules/menu/main.html.twig', [
  33.             'cache' => $menu
  34.         ]);
  35.     }
  36.     
  37. }