<?php
class CategoryController extends BaseController {
public function indexAction()
{
$_category = $this->dispatcher->getParam('category', 'int');
$category = Categories::findFirstById($_category) ;
if(!$category){
$this->response->redirect();
$this->view->disable();
}
$_videos = $this->cached->get('category.'.$_category.'.cache');
if ($_videos === NULL) {
$_videos = Videos::findByCategory($_category) ;
$this->cached->save('category.'.$_category.'.cache', $_videos);
}
$videos = new \Phalcon\Paginator\Adapter\Model(
[
'data' => $_videos,
'limit' => $this->config->application->onPage,
'page' => $this->dispatcher->getParam('page', 'int') ?: 1
]
);
$this->view->setVars([
'videos' => $videos->getPaginate(),
'category' => $category
]);
}
}