src/AMZ/Core/Controller/FrontendController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\AMZ\Core\Controller;
  3. use App\AMZ\Core\Entity\Category;
  4. use App\AMZ\Core\Entity\Post;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Twig\Environment;
  9. class FrontendController extends AbstractController
  10. {
  11.     protected $doctrine;
  12.     protected $twig;
  13.     protected $paginator;
  14.     const THEME 'ismart';
  15.     public function __construct(ManagerRegistry $managerRegistryEnvironment $twigPaginatorInterface $paginator)
  16.     {
  17.         $this->doctrine $managerRegistry;
  18.         $this->twig $twig;
  19.         $this->paginator $paginator;
  20.     }
  21.     protected function getTemplateByCategory(Category $category){
  22.         $type $category->getPostType();
  23.         $slug $category->getSlug();
  24.         $tmpType "default";
  25.         $templates $this->getParameter('templates');
  26.         if(isset($templates[$type])){
  27.             $tmpType $templates[$type];
  28.         }
  29.         $template 'themes/'.self::THEME.'/post/'.$tmpType.'/category.html.twig';
  30.         $categoryTemplate 'themes/'.self::THEME.'/post/'.$tmpType.'/category/'.$slug.'.html.twig';
  31.         if($this->twig->getLoader()->exists($categoryTemplate)){
  32.             $template $categoryTemplate;
  33.         }
  34.         return $template;
  35.     }
  36.     protected function getTemplateByPost(Post $post){
  37.         $type $post->getPostType();
  38.         $slug $post->getSlug();
  39.         $templates $this->getParameter('templates');
  40.         $tmpType $templates['default'];
  41.         if(isset($templates[$type])){
  42.             $tmpType $templates[$type];
  43.         }
  44.         $template 'themes/'.self::THEME.'/post/'.$tmpType.'/detail.html.twig';
  45.         $postTemplate 'themes/'.self::THEME.'/post/'.$tmpType.'/'.$slug.'.html.twig';
  46.         if($this->twig->getLoader()->exists($postTemplate)){
  47.             $template $postTemplate;
  48.         }
  49.         return $template;
  50.     }
  51. }