From 222038734da1018f03c27b9e7c86a7aff06c468f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 7 May 2015 23:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=89=8D=E7=BD=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=AE=9A=E4=B9=89=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/controller.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/library/think/controller.php b/library/think/controller.php index 4ac9f969..9de09bba 100644 --- a/library/think/controller.php +++ b/library/think/controller.php @@ -25,10 +25,40 @@ class Controller { // 模板引擎参数 $this->view = new View(); - //控制器初始化 + // 控制器初始化 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]); + } } /**