src/Controller/NewController.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Pimcore\Model\DataObject;
  8. date_default_timezone_set('Europe/Brussels');
  9. class NewController extends FrontendController
  10. {
  11.     /**
  12.      * @Template
  13.      * @param Request $request
  14.      * @return array
  15.      */
  16.     public function listAction(Request $request\Knp\Component\Pager\PaginatorInterface $paginator)
  17.     {
  18.         
  19.         $news = new DataObject\News\Listing();
  20.         $news->setOrderKey('date');
  21.         $news->setOrder('Desc');
  22.         $news->load();
  23.         $countPerPage intval($this->document->getProperty("newItemCountPerPage"));
  24.         if(!$countPerPage) :
  25.             $countPerPage 3;
  26.         endif;
  27.         $paginator $paginator->paginate(
  28.             $news,
  29.             $request->get('page'1),
  30.             $countPerPage
  31.         );
  32.         return $this->render('news/list.html.twig', [
  33.             'paginator' => $paginator,
  34.             'paginationVariables' => $paginator->getPaginationData(),
  35.             'news' => $news
  36.         ]);
  37.         
  38.     }
  39.   
  40.     /**
  41.      * @Template
  42.      * @param Request $request
  43.      * @route("/{_locale}/actualites/{slug}/{id}", name="newsDetail",methods={"GET"})
  44.      * @return array
  45.      */
  46.     public function detailAction(Request $request)
  47.     {
  48.         $id $request->get('id');
  49.         $new DataObject\News::getById($id);
  50.         return $this->render('news/detail.html.twig', [
  51.             'new' => $new
  52.         ]);
  53.     }
  54.     /**
  55.      * @Template
  56.      * @param Request $request
  57.      * @return array
  58.      */
  59.     public function snippetAction(Request $request)
  60.     {
  61.         $lastnew = new DataObject\News\Listing();
  62.         $lastnew->setOrderKey('date');
  63.         $lastnew->setOrder('Desc');
  64.         $lastnew->setLimit(3);
  65.         $lastnew->load();
  66.         return $this->render('snippets/last-news.html.twig', [
  67.             'lastnew' => $lastnew
  68.         ]);
  69.     }
  70. }