예제 #1
0
 public function showAction()
 {
     $id = $this->dispatcher->getParam('id');
     $post = Posts::findFirstByid($id);
     if (!$post) {
         return $this->response->redirect("index");
     }
     $this->view->post = $post;
 }
예제 #2
0
 /**
  * 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();
 }
예제 #3
0
 public function deleteAction($id)
 {
     $post = Posts::findFirstById($id);
     if (!$post) {
         $this->flash->error(_("Post was not found"));
         return $this->dispatcher->forward(array('action' => 'index'));
     }
     if (!$post->delete()) {
         $this->flash->error($post->getMessages());
     } else {
         $this->flash->success(_("Post was deleted"));
     }
     return $this->dispatcher->forward(array('action' => 'index'));
 }