/** * Displays post by category * @param [int] $categoryId [description category id] * @param [string] $slug [description slug seo] * @return [array] [list all object ] */ public function categoryAction($categoryId, $slug) { $category = Categories::findFirstById($categoryId); if (!$category) { $this->flashSession->notice('The category doesn\'t exist'); return $this->response->redirect(); } $numberPage = 1; if ($this->request->getQuery("page", "int")) { $numberPage = $this->request->getQuery("page", "int"); } $posts = Posts::find("categoriesId = '{$categoryId}'"); $paginator = new Paginator(array("data" => $posts, "limit" => 10, "page" => $numberPage)); $this->view->page = $paginator->getPaginate(); $this->view->categories = Categories::find(); }
public function searchAction() { $request = $this->request; $searchParams = null; $numberPage = 1; if ($request->isPost()) { $query = Criteria::fromInput($this->di, 'Phalconvn\\Models\\Posts', $this->request->getPost()); $this->persistent->searchParams = $query->getParams(); } else { $numberPage = $this->request->getQuery("page", "int"); } $parameters = array("order" => "created DESC"); if ($this->persistent->searchParams == true) { $parameters = $this->persistent->searchParams; } $posts = Posts::find($parameters); if (count($posts) == 0) { $this->flash->notice("The search did not find any Posts"); return $this->dispatcher->forward(array("action" => "index")); } // echo $posts->posts->id; $paginator = new Paginator(array("data" => $posts, "limit" => 10, "page" => $numberPage)); $this->view->page = $paginator->getPaginate(); }