Exemplo n.º 1
0
 /**
  * Deletes a post
  *
  * @param string $id
  */
 public function deleteAction($id)
 {
     $post = Posts::findFirstByid($id);
     if (!$post) {
         $this->flash->error("post was not found");
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
     }
     if (!$post->delete()) {
         foreach ($post->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "search"));
     }
     $this->flash->success("post was deleted successfully");
     return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
 }
Exemplo n.º 2
0
 /**
  * Shows a post
  *
  * @param string $id
  */
 public function showAction($id)
 {
     $cache = $this->di->get('viewCache');
     $key = $this->createKey('posts', 'show', array($id));
     $post = $cache->get($key);
     if ($post === null) {
         $post = Posts::findFirstByid($id);
         $cache->save($key, $post);
     }
     if (!$post) {
         $this->flashSession->error("post was not found");
         $response = new \Phalcon\Http\Response();
         $response->setStatusCode(404, "Not Found");
         return $response->redirect("posts/index");
     }
     $this->tag->prependTitle($post->title . " - ");
     $this->view->post = $post;
 }