AboutController.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/3
* Time: 19:46
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;
class AboutController extends AdminBaseController
{
public function index(){
$data=Db::name('about')
->where('id',1)
->paginate(10);
$this->assign([
'data'=>$data,
'page'=>$data->render(),
]);
return $this->fetch();
}
//编辑
public function edit(){
$id=$this->request->param('id', 0, 'intval');
if($this->request->isPost()){
$param=$this->request->param();
$validate = new Validate([
'thumbnail' => 'require',
'content' => 'require',
]);
$validate->message([
'thumbnail'=>'请上传缩略图!',
'content' => '请输入页面内容!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$param['update_time']=time();
Db::name('about')
->where('id',$id)
->update($param);
$this->success('更新成功!');
}else{
$data=Db::name('about')
->where("id",$id)
->find();
$this->assign([
'data'=>$data,
]);
return $this->fetch();
}
}
}