Beispiel #1
0
 public static function edit_action()
 {
     // 拦截
     self::role('member');
     $comment = comment_model::get_by_id(g_int('id'));
     self::forward_404_if($comment === null, '评论不存在');
     if (visitor::is_post()) {
         // 拦截
         self::csrf('member');
         try {
             // 校验
             $checker = new lazy_checker(p());
             $checker->check_model_rules('comment');
             // 执行
             $comment->add_props($checker->get_all());
             $comment->save();
             // 成功
             self::json_result(true, '评论编辑成功。', 0, url('post/show?id=' . $comment->post_id));
         } catch (check_failed $e) {
             // 失败
             self::json_result(false, $e->get_reasons());
         }
     } else {
         // 呈现
         self::set('comment', $comment);
         self::show_page('', 'two');
     }
 }
Beispiel #2
0
 public static function delete($comment_id)
 {
     $comment = comment_model::get_by_id($comment_id);
     if ($comment !== null) {
         comment_model::del_by_id($comment_id);
         post_model::dec_by_id(array('comment_count' => 1), $comment->post_id);
     }
 }