直接点击 lumen 路由控制器跳转到相关文件
在 lumen 中设置路由时,可以通过以下方式直接点击控制器跳转到相关文件:
在 bootstrap/app.php 中修改 $app 变量的初始化:
$app = new class (dirname(__dir__)) extends laravel\lumen\application { protected function callactiononarraybasedroute($routeinfo) { $action = $routeinfo[1]['target'] ?? $routeinfo[1]; if ( is_array($action) && count($action) === 2 && class_exists($action[0]) && method_exists($action[0], $action[1]) ) { try { [$controller, $method] = $action; return $this->prepareresponse($this->call([$this->make($controller), $method], $routeinfo[2])); } catch (httpresponseexception $e) { return $e->getresponse(); } } return parent::callactiononarraybasedroute($routeinfo); } };
之后便可以在路由中以如下方式定义:
$router->get('/foo', [ 'target' => ['\App\Http\Controllers\ExampleController', 'index'] ]); $router->get('/foo', ['\App\Http\Controllers\ExampleController', 'index']);
ide 即可支持跳转和提示功能。
注意:
以上就是Lumen路由控制器跳转:如何实现IDE直接跳转及提示?的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号