示例#1
0
 public function create()
 {
     $error = false;
     $status = false;
     $post_id = isset($this->params['id']) ? (int) $this->params['id'] : 0;
     $post = Post::findOne($post_id);
     $comment = $post->comments->getNew();
     if (!$post) {
         $error = 'Could not post comment because the associated post could not be found.';
     }
     if (!$error && !$comment) {
         $error = 'Could not create a new comment for this post.';
     }
     if (!$error) {
         $comment->poster = $_POST['poster'];
         $comment->content = $_POST['comment'];
         $comment->timestamp = time();
         $comment->status = 0;
         $status = $comment->save();
         if (!$status) {
             $error = 'Unable to save comment at this time, please try again later.';
         }
     }
     echo json_encode(['status' => $status, 'error' => $error]);
 }
示例#2
0
 public function edit()
 {
     $post_id = isset($this->params['id']) ? (int) $this->params['id'] : 0;
     if (!$post_id || !($post = Post::findOne($post_id))) {
         throw new GeneralException('Post not found');
     }
     $this->view->visible(['title' => 'Edit: ' . $post->title])->raw(['post' => $post])->render('posts/edit');
 }