添加前置操作定义支持

This commit is contained in:
thinkphp
2015-05-07 23:20:07 +08:00
parent 69c526ebb5
commit 222038734d

View File

@@ -29,6 +29,36 @@ class Controller {
if(method_exists($this, '_initialize')){ if(method_exists($this, '_initialize')){
$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]);
}
} }
/** /**