| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\Db;
- class KnowController extends AdminBaseController{
- public function index(){
- $lists = Db::name('know')->order('id desc')->paginate(20);
- $this->assign('lists',$lists);
- return $this->fetch();
- }
- public function add(){
- return $this->fetch();
- }
- public function addPost(){
- $param = $this->request->param();
- $param['create_time'] = time();
- if($param['author']!=''){
- $param['answer_time'] = time()+rand(3600*24,3600*100);
- }
- $res = Db::name('know')->insert($param);
- if($res){
- $this->success('添加成功');
- }else{
- $this->error('添加失败');
- }
- }
- public function edit(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('需要id');
- $info = Db::name('know')->where('id',$param['id'])->find();
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function editPost(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('需要id');
- $res = Db::name('know')->update($param);
- if($res){
- $this->success('编辑成功');
- }else{
- $this->error('编辑失败');
- }
- }
- public function delete(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('需要id');
- $res = Db::name('know')->where('id',$param['id'])->delete();
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- }
- ?>
|