public function listAction() { $params = $this->request->getQuery(); if ($params['_url'] != null) { $string = ltrim($params['_url'], '/danh-muc'); } $array = explode('-', $string); $id = $array[0]; // Get name category $category = Category::findFirstById($id); $this->tag->setTitle($category->name); // Get list category of id if ($id != '' && $id > 0) { // The data set to paginate $news = News::find(array('active = 1 AND category =' . $id, 'order' => 'id DESC')); $currentPage = (int) $_GET["page"]; // Create a Model paginator, show 10 rows by page starting from $currentPage $paginator = new PaginatorModel(array("data" => $news, "limit" => 13, "page" => $currentPage)); // Get the paginated results $page = $paginator->getPaginate(); $this->view->setVar('page', $page); $this->view->setVar('category', $category); } else { $this->response->redirect('error'); } }
public function editAction($id) { if (!$this->request->isPost()) { $category = Category::findFirstById($id); if (!$category) { $this->flash->error("该分类不存在"); return $this->forward("category/index"); } $this->view->form = new CategoryForm($category, array('edit' => true)); } }