不知道什么时候开始的 __construct方法中使用request()后得不到该有的结果
namespace app\backend\controller;
public function __construct()
{
$request = request();
echo 'init:';
echo PHP_EOL;
var_dump($request->action);
echo PHP_EOL;
parent::__construct();
//得到默认的 where条件
$this->where = $this->getWhere();
}
route配置未配置路由
use Webman\Route;
Route::any('/', function ($request) {
return response('hello');
});
// 适配api目录版本控制器
Route::any('/api/v1/{controller}/{action}', function($request, $controller, $action){
$class_name = 'app\\api\\v1\\controller\\' . $controller;
$request->controller = $class_name;
$request->action = $action;
$request->app = 'api';
$controller = new $class_name;
return call_user_func([$controller, $action], $request);
});
/*
Route::any('/backend/{controller}/{action}', function($request, $controller, $action){
$class_name = 'app\\backend\\controller\\' . $controller;
$request->controller = $class_name;
$request->action = $action;
//$request->app = 'backend';
$controller = new $class_name;
return call_user_func([$controller, $action], $request);
});
*/
控制台打印
init:
NULL
我记得以前是可以的,当我打开route.php中关于backend的注释的时候,控制台打印
init:
string(5) "lists"
base:
string(5) "lists"
getWhere:
string(5) "lists"
init:
string(5) "lists"
base:
string(5) "lists"
getWhere:
string(5) "lists"
route.php 配置
use Webman\Route;
Route::any('/', function ($request) {
return response('hello');
});
// 适配api目录版本控制器
Route::any('/api/v1/{controller}/{action}', function($request, $controller, $action){
$class_name = 'app\\api\\v1\\controller\\' . $controller;
$request->controller = $class_name;
$request->action = $action;
$request->app = 'api';
$controller = new $class_name;
return call_user_func([$controller, $action], $request);
});
Route::any('/backend/{controller}/{action}', function($request, $controller, $action){
$class_name = 'app\\backend\\controller\\' . $controller;
$request->controller = $class_name;
$request->action = $action;
//$request->app = 'backend';
$controller = new $class_name;
return call_user_func([$controller, $action], $request);
});
我该如何处理这个问题,保证后续的框架变动影响不到我一开始想要达到的结果