BaseController.php
2.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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace cmf\controller;
use think\Controller;
use think\Request;
use think\View;
use think\Config;
class BaseController extends Controller
{
/**
* 构造函数
* @param Request $request Request对象
* @access public
*/
public function __construct(Request $request = null)
{
if (!cmf_is_installed() && $request->module() != 'install') {
header('Location: ' . cmf_get_root() . '/?s=install');
exit;
}
if (is_null($request)) {
$request = Request::instance();
}
$this->request = $request;
$this->_initializeView();
$this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));
// 控制器初始化
$this->_initialize();
// 前置操作方法
if ($this->beforeActionList) {
foreach ($this->beforeActionList as $method => $options) {
is_numeric($method) ?
$this->beforeAction($options) :
$this->beforeAction($method, $options);
}
}
}
// 初始化视图配置
protected function _initializeView()
{
}
/**
* 排序 排序字段为list_orders数组 POST 排序字段为:list_order
*/
protected function listOrders($model)
{
if (!is_object($model)) {
return false;
}
$pk = $model->getPk(); //获取主键名称
$ids = $this->request->post("list_orders/a");
if (!empty($ids)) {
foreach ($ids as $key => $r) {
$data['list_order'] = $r;
$model->where([$pk => $key])->update($data);
}
}
return true;
}
}