コード例 #1
0
ファイル: IndexController.php プロジェクト: kjmtrue/blog
 /**
  * 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();
 }
コード例 #2
0
ファイル: PostsController.php プロジェクト: kjmtrue/blog
 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();
 }