diff --git a/library/think/Request.php b/library/think/Request.php index c34a4b14..a73b4fa5 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -115,6 +115,8 @@ class Request protected $filter; // Hook扩展方法 protected static $hook = []; + // 绑定的属性 + protected $bind = []; /** * 架构函数 @@ -1436,4 +1438,30 @@ class Request Session::set($name, $token); return $token; } + + /** + * 设置当前请求绑定的对象实例 + * @access public + * @param string $name 绑定的对象标识 + * @param mixed $obj 绑定的对象实例 + * @return mixed + */ + public function bind($name, $obj = null) + { + if (is_array($name)) { + $this->bind = array_merge($this->bind, $name); + } else { + $this->bind[$name] = $obj; + } + } + + public function __set($name, $value) + { + $this->bind[$name] = $value; + } + + public function __get($name) + { + return isset($this->bind[$name]) ? $this->bind[$name] : null; + } } diff --git a/library/think/Route.php b/library/think/Route.php index dfbb5b81..50563671 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1367,7 +1367,7 @@ class Route $bind[$key] = $result; } } - $matches = array_merge($matches, $bind); + Request::instance()->bind($bind); } // 解析额外参数