CooperationController.php
3.3 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
98
<?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\admin\controller;
use cmf\controller\AdminBaseController;
use app\admin\model\CooperationModel;
class CooperationController extends AdminBaseController
{
protected $targets = ["_blank" => "新标签页打开", "_self" => "本窗口打开"];
//首页
public function index(){
$CooperationModel = new CooperationModel();
$cooperation = $CooperationModel->order('weigh desc')->select();
$this->assign('cooperation', $cooperation);
return $this->fetch();
}
//添加页面
public function add(){
$this->assign('targets', $this->targets);
return $this->fetch();
}
//提交保存
public function addPost(){
$data = $this->request->param();
$CooperationModel = new CooperationModel();
$result = $this->validate($data, 'Cooperation');
if ($result !== true) {
$this->error($result);
}
$CooperationModel->allowField(true)->save($data);
$this->success("添加成功!", url("Cooperation/index"));
}
//编辑页面
public function edit(){
$id = $this->request->param('id', 0, 'intval');
$CooperationModel = new CooperationModel();
$cooperation = $CooperationModel->get($id);
$this->assign('targets', $this->targets);
$this->assign('cooperation', $cooperation);
return $this->fetch();
}
//编辑保存页面
public function editPost()
{
$data = $this->request->param();
$CooperationModel = new CooperationModel();
$result = $this->validate($data, 'Cooperation');
if ($result !== true) {
$this->error($result);
}
$CooperationModel->allowField(true)->isUpdate(true)->save($data);
$this->success("保存成功!", url("Cooperation/index"));
}
//删除
public function delete(){
$id = $this->request->param('id', 0, 'intval');
CooperationModel::destroy($id);
$this->success("删除成功!", url("Cooperation/index"));
}
//显示与隐藏
public function toggle()
{
$data = $this->request->param();
$CooperationModel = new CooperationModel();
if (isset($data['ids']) && !empty($data["display"])) {
$ids = $this->request->param('ids/a');
$CooperationModel->where('id', 'in', $ids)->update(['status' => 1]);
$this->success("更新成功!");
}
if (isset($data['ids']) && !empty($data["hide"])) {
$ids = $this->request->param('ids/a');
$CooperationModel->where('id', 'in', $ids)->update(['status' => 0]);
$this->success("更新成功!");
}
}
}