mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
Controller类架构方法增加request参数 改进App类
This commit is contained in:
@@ -163,7 +163,7 @@ class App
|
|||||||
{
|
{
|
||||||
if (empty($vars)) {
|
if (empty($vars)) {
|
||||||
// 自动获取请求变量
|
// 自动获取请求变量
|
||||||
$vars = Request::instance()->param();
|
$vars = Request::param();
|
||||||
}
|
}
|
||||||
if (is_array($method)) {
|
if (is_array($method)) {
|
||||||
$class = is_object($method[0]) ? $method[0] : new $method[0];
|
$class = is_object($method[0]) ? $method[0] : new $method[0];
|
||||||
@@ -193,8 +193,9 @@ class App
|
|||||||
if ($reflect->getNumberOfParameters() > 0) {
|
if ($reflect->getNumberOfParameters() > 0) {
|
||||||
$params = $reflect->getParameters();
|
$params = $reflect->getParameters();
|
||||||
foreach ($params as $param) {
|
foreach ($params as $param) {
|
||||||
$name = $param->getName();
|
$name = $param->getName();
|
||||||
if ('think\Request' == $param->getClass()->name) {
|
$class = $param->getClass();
|
||||||
|
if ($class && 'think\Request' == $class->getName()) {
|
||||||
$args[] = Request::instance();
|
$args[] = Request::instance();
|
||||||
} elseif (1 == $type && !empty($vars)) {
|
} elseif (1 == $type && !empty($vars)) {
|
||||||
$args[] = array_shift($vars);
|
$args[] = array_shift($vars);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace think;
|
|||||||
|
|
||||||
\think\Loader::import('controller/Jump', TRAIT_PATH, EXT);
|
\think\Loader::import('controller/Jump', TRAIT_PATH, EXT);
|
||||||
|
|
||||||
|
use think\Request;
|
||||||
use think\View;
|
use think\View;
|
||||||
|
|
||||||
class Controller
|
class Controller
|
||||||
@@ -21,6 +22,8 @@ class Controller
|
|||||||
|
|
||||||
// 视图类实例
|
// 视图类实例
|
||||||
protected $view = null;
|
protected $view = null;
|
||||||
|
// Request实例
|
||||||
|
protected $request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前置操作方法列表
|
* 前置操作方法列表
|
||||||
@@ -33,9 +36,10 @@ class Controller
|
|||||||
* 架构函数
|
* 架构函数
|
||||||
* @access public
|
* @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')) {
|
if (method_exists($this, '_initialize')) {
|
||||||
|
|||||||
@@ -313,11 +313,11 @@ class Loader
|
|||||||
}
|
}
|
||||||
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$action = new $class;
|
$action = new $class(Request::instance());
|
||||||
$_instance[$name . $layer] = $action;
|
$_instance[$name . $layer] = $action;
|
||||||
return $action;
|
return $action;
|
||||||
} elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) {
|
} elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) {
|
||||||
return new $emptyClass;
|
return new $emptyClass(Request::instance());
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('class [ ' . $class . ' ] not exists', 10001);
|
throw new Exception('class [ ' . $class . ' ] not exists', 10001);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user