示例#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 index()
 {
     $page = isset($this->params['page']) ? (int) $this->params['page'] : 1;
     $posts = ResultCache::get('posts_' . $page, function () use($page) {
         return Post::paginate($page)->order_by('timestamp', 'desc')->fetch();
     });
     $this->view->visible(['title' => 'Posts By Ryan Wagner', 'posts' => $posts])->render('posts/page');
 }
示例#3
0
 public function home()
 {
     Post::update();
     $this->view->visible(['title' => 'Home Page', 'session' => $this->session])->render('pages/home');
 }