php class CategoryController extends BaseController public function in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?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
]);
}
}