Example #1
0
 public function action_edit_reply()
 {
     if (Auth::instance()->logged_in()) {
         $reply_id = $this->request->param('id');
         $reply = new Model_Reply();
         $view = View::factory('topic/edit_reply');
         $view->replies = $reply->get_reply($reply_id);
         $this->template->content = $view->render();
         if ($this->request->method() === Request::POST) {
             if (!Security::check($this->request->param('id2'))) {
                 throw new Exception("Bad token!");
             }
             $content = $this->request->post('content');
             $topic_id = $this->request->post('topic_id');
             //Topic id for last param from redirect.
             if (empty($content)) {
                 throw new Exception("Content of your reply must not be empty!");
             }
             $reply = new Model_Reply();
             $reply_id = $this->request->param('id');
             $update_reply = $reply->update($content, $reply_id);
             if (!$update_reply) {
                 throw new Exception("Reply will not be updated");
             }
             $this->redirect('topic/view/' . $topic_id);
         }
     }
 }