baodinzhihui/app/controller/manager/Base.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2021-08-09 02:38:25 +00:00
<?php
namespace app\controller\manager;
use app\controller\BaseController;
/**
* 控制器基础类
*/
class Base extends BaseController
{
protected $data = [];
protected function initialize()
{
$this->middleware = [
'csrf',
'auth' => [
'except' => ['manager.login/index']
]
];
$auth = session('auth');
$this->data['member'] = $auth;
if(session('?__token__')){
$this->data['_token'] = session('__token__');
}else{
$this->data['_token'] = $this->request->buildToken();
}
$this->data['groupId'] = $auth['groupId'] ?? 0;
}
//变量赋值到模板
protected function view()
{
return view()->assign($this->data);
}
protected function error($msg = '', string $url = null, $data = '', int $wait = 3)
{
if (is_null($url)) {
$url = $this->request->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ($url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
return $this->redirect(url('manager.error/jump', $result));
}
}