mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 14:52:47 +08:00
添加前置操作定义支持
This commit is contained in:
@@ -29,6 +29,36 @@ class Controller {
|
||||
if(method_exists($this, '_initialize')){
|
||||
$this->_initialize();
|
||||
}
|
||||
// 前置操作方法
|
||||
$list = Config::get('before_action_list');
|
||||
if($list){
|
||||
foreach($list as $config){
|
||||
$this->beforeAction($config['method',$config['option']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置操作
|
||||
* @access public
|
||||
* @param $method
|
||||
* @param $options
|
||||
*/
|
||||
protected function beforeAction($method, $options) {
|
||||
if (isset($options['only'])) {
|
||||
if (!in_array(ACTION_NAME, $options['only'])) {
|
||||
return;
|
||||
}
|
||||
} elseif (isset($options['except'])) {
|
||||
if (in_array(ACTION_NAME, $options['except'])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
call_user_func([$this, $method]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user