public function edit() { $id = I('id'); $model = new PostModel(); $post = $model->find($id); if (empty($post)) { $this->error('帖子不存在'); } $this->assign('post', $post); $this->display(); }
/** * 删除帖子 */ public function postDelete() { $this->checkLogin(); $id = I('id'); $model = new PostModel(); $post = $model->find($id); if (empty($post)) { $this->error('帖子不存在'); } if ($post['userId'] != $this->user['userId']) { $this->error('你无权删除'); } $result = $model->delete($id); if ($result === false) { $this->error('删除失败'); } else { $callback = I('callback'); if (empty($callback)) { $callback = U('posts'); } $this->success('删除成功', $callback); } }