Beispiel #1
0
 public function action_comment($slug)
 {
     $post = Model_Post::find_by_slug($slug);
     // Lazy validation
     if (Input::post('name') and Input::post('email') and Input::post('message')) {
         // Create a new comment
         $post->comments[] = new Model_Comment(array('name' => Input::post('name'), 'website' => Input::post('website'), 'email' => Input::post('email'), 'message' => Input::post('message'), 'user_id' => $this->current_user->id));
         // Save the post and the comment will save too
         if ($post->save()) {
             $comment = end($post->comments);
             Session::set_flash('success', 'Added comment #' . $comment->id . '.');
         } else {
             Session::set_flash('error', 'Could not save comment.');
         }
         Response::redirect('blog/view/' . $slug);
     } else {
         // Just show the view again until they get it right
         $this->action_view($slug);
     }
 }