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); }