From 62debf4bc65aadecbbdb82e36e7126358bdbe24e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 27 May 2016 11:30:05 +0800 Subject: [PATCH] =?UTF-8?q?Controller=E7=B1=BB=E6=9E=B6=E6=9E=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=A2=9E=E5=8A=A0request=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 7 ++++--- library/think/Controller.php | 8 ++++++-- library/think/Loader.php | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 9d545d8f..8aa14a43 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -163,7 +163,7 @@ class App { if (empty($vars)) { // 自动获取请求变量 - $vars = Request::instance()->param(); + $vars = Request::param(); } if (is_array($method)) { $class = is_object($method[0]) ? $method[0] : new $method[0]; @@ -193,8 +193,9 @@ class App if ($reflect->getNumberOfParameters() > 0) { $params = $reflect->getParameters(); foreach ($params as $param) { - $name = $param->getName(); - if ('think\Request' == $param->getClass()->name) { + $name = $param->getName(); + $class = $param->getClass(); + if ($class && 'think\Request' == $class->getName()) { $args[] = Request::instance(); } elseif (1 == $type && !empty($vars)) { $args[] = array_shift($vars); diff --git a/library/think/Controller.php b/library/think/Controller.php index 8dafcbbe..db0dc194 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -13,6 +13,7 @@ namespace think; \think\Loader::import('controller/Jump', TRAIT_PATH, EXT); +use think\Request; use think\View; class Controller @@ -21,6 +22,8 @@ class Controller // 视图类实例 protected $view = null; + // Request实例 + protected $request; /** * 前置操作方法列表 @@ -33,9 +36,10 @@ class Controller * 架构函数 * @access public */ - public function __construct() + public function __construct(Request $request) { - $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); + $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); + $this->request = $request; // 控制器初始化 if (method_exists($this, '_initialize')) { diff --git a/library/think/Loader.php b/library/think/Loader.php index 4509c58b..f271a6b4 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -313,11 +313,11 @@ class Loader } $class = self::parseClass($module, $layer, $name, $appendSuffix); if (class_exists($class)) { - $action = new $class; + $action = new $class(Request::instance()); $_instance[$name . $layer] = $action; return $action; } elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) { - return new $emptyClass; + return new $emptyClass(Request::instance()); } else { throw new Exception('class [ ' . $class . ' ] not exists', 10001); }