关于发表新帖子\n public function post_add_do(){\n $data=[\n ‘title’=>input(‘post.title’),\n ‘desc’=>input(‘post.desc’),\n ‘cate_id’=>input(‘post.cate_id’),\n ‘user_id’=>session(‘user.id’),\n ‘create_time’=>time()\n ];\n $res=Db::name(‘post’)->insert($data);\n if($res){\n $this->success(‘发表成功’,’index/index/index’);\n }else{\n $this->error(‘发表失败’);\n }\n }\n //查看帖子详情\n public function post_detail(){\n $post_id=input(‘param.post_id’);\n $post_info=Db::name(‘post’)->find($post_id);\n //halt($post_info);\n //查询用户信息\n $user_info=Db::name(‘user’)->find($post_info[‘user_id’]);\n $this->assign(‘post_info’,$post_info);\n $this->assign(‘user_info’,$user_info);\n return view();\n }\n //添加评论\n public function comment_add(){\n $data=[\n ‘post_id’=>input(‘post.post_id’),\n ‘desc’=>input(‘post.desc’),\n ‘user_id’=>session(‘user.id’),\n ‘create_time’=>time()\n ];\n $res=Db::name(‘comment’)->insert($data);\n if($res){\n $this->success(‘评论成功’,’index/index/index’);\n }else{\n $this->error(‘评论失败’);\n }\n }\n //收藏帖子\n public function collect(){\n $data=[\n ‘post_id’=>input(‘post.post_id’),\n ‘user_id’=>session(‘user.id’),\n ‘create_time’=>time()\n ];\n //判断是否收藏\n $where=[\n ‘post_id’=>input(‘post.post_id’),\n ‘user_id’=>session(‘user.id’)\n ];\n $res=Db::name(‘collect’)->where($where)->find();\n if($res){\n $this->error(‘已收藏,无需重复收藏’);\n }\n $res=Db::name(‘collect’)->insert($data);\n if($res){\n $this->success(‘收藏成功’,’index/index/index’);\n }else{\n $this->error(‘收藏失败’);\n }\n }\n //取消收藏\n public function uncollect(){\n $where=[\n ‘post_id’=>input(‘post.post_id’),\n ‘user_id’=>session(‘user.id’)\n ];\n $res=Db::name(‘collect’)->where($where)->delete();\n if($res){\n $this->success(‘取消收藏成功’,’index/index/index’);\n }else{\n $this->error(‘取消收藏失败’);\n }\n }\n //删除帖子\n public function post_del(){\n $post_id=input(‘post.post_id’);\n $res=Db::name(‘post’)->delete($post_id);\n if($res){\n $this->success(‘删除成功’,’index/index/index’);\n }else{\n $this->error(‘删除失败’);\n }\n }\n //编辑帖子\n public function post_edit(){\n $post_id=input(‘param.post_id’);\n $post_info=Db::name(‘post’)->find($post_id);\n $this->assign(‘post_info’,$post_info);\n return view();\n }\n //编辑帖子处理\n public function post_edit_do(){\n $post_id=input(‘post.post_id’);\n $data=[\n ‘title’=>input(‘post.title’),\n ‘desc’=>input(‘post.desc’),\n ‘cate_id’=>input(‘post.cate_id’)\n ];\n $res=Db::name(‘post’)->where(‘id’,$post_id)->update($data);\n if($res){\n $this->success(‘编辑成功’,’index/index/index’);\n }else{\n $this->error(‘编辑失败’);\n }\n }\n}