AdminRotationController.php
2.8 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\RotationModel;
use cmf\controller\AdminBaseController;
use think\Db;
class AdminRotationController extends AdminBaseController
{
//轮播图
//列表
public function index(){
$res = Db::name('rotation')
->order('id desc')
->paginate(10);
$data = $res->toArray();
$data = $data['data'];
$page = $res->render();
$this->assign('list',$data);
$this->assign('page',$page);
return $this->fetch();
}
//添加页面
public function add(){
return $this->fetch();
}
//添加提交
public function addPost(){
$data = $this->request->param();
$result = $this->validate($data, 'AdminRotation.add');
if ($result !== true) {
$this->error($result);
}
$rotationModel = new RotationModel();
$res = $rotationModel->create($data);
if($res){
$this->success('添加成功!', url('AdminRotation/index'));
}else{
$this->error('失败');
}
}
//编辑页面
public function edit(){
$id = $this->request->param('id');
$post = Db::name('rotation')
->where(['id'=>$id])
->find();
$this->assign('post',$post);
return $this->fetch();
}
//编辑提交
public function editPost(){
$data = $this->request->param();
$result = $this->validate($data, 'AdminRotation.edit');
if ($result !== true) {
$this->error($result);
}
$rotationModel = new RotationModel();
// 显式指定更新数据操作
$res = $rotationModel->isUpdate(true)->save($data);
if($res){
$this->success('保存成功!', url('AdminRotation/index'));
}else{
$this->error('失败');
}
}
//删除
public function delete(){
$id = $this->request->param('id');
$rotationModel = new RotationModel();
$res = $rotationModel->where(['id'=>$id])->delete();
if($res){
$this->success('删除成功!');
}else{
$this->error('失败');
}
}
}