BaseController.php
907 字节
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
<?php
namespace app\web\controller;
use think\Request;
use think\Session;
use think\Validate;
use think\Controller as thinkController;
use app\common\service\Render as RenderTrait;
class BaseController extends thinkController
{
use RenderTrait;
const SUCCESS_CODE = 0;
/**
* 登录验证
*/
public function _initialize()
{
$user = Session::get('name');
if($user === ''){
// if (Session::get('name')) {
return Request::instance()->isAjax() ? json($this->renderError('您尚未登录系统')) : $this->redirect(url('web/index/login'));
}
}
/**
* 表单验证
*/
public function formValidate($data, $rules, $message)
{
$validate = new Validate($rules, $message);
if (!$validate->check($data)) {
return $validate->getError();
}
return null;
}
}