lumen怎么得到当前Uri的控制器、Action、路由规则
2024-10-06 20:17:36
<?php namespace App\Http\Controllers; class HelloController extends Controller
{
public function index()
{
// 当前path
$router = explode("?", $request->getRequestUri())[0];
// 所有的router
$rts = app()->getRoutes();
// 当前route---做seo定制url时这个方法很有用
$routeInfo = app('request')->route();
$rows = [];
foreach ($rts as $rt => $route ) {
$rows[$route['uri']] = [
'verb' => $route['method'],
'uri' => $route['uri'],
'uses' => isset($route['action']['uses']) ? $route['action']['uses'] : 'Closure',
'controller' => $this->getController($route['action']),
'action' => $thiw->getAction($route['action']),
];
} print_r($rows);
return;
} /**
* @param array $action
* @return mixed|string
*/
protected function getAction(array $action)
{
if (!empty($action['uses'])) {
$data = $action['uses'];
if (($pos = strpos($data, "@")) !== false) {
return substr($data, $pos + 1);
} else {
return "METHOD NOT FOUND";
}
} else {
return 'Closure';
}
} /**
* @param array $action
* @return mixed|string
*/
protected function getController(array $action)
{
if (empty($action['uses'])) {
return 'Closure';
} return current(explode("@", $action['uses']));
} }
最新文章
- 如何刷新DNS缓存
- maven项目下jsp文件中el表达式失效问题
- Codeforces Round #345 D. Image Preview(二分)
- [3D跑酷] MissionManager
- Js document.frmLogin.action = &#39;/login.htm&#39;;的意义和form表单的target属性
- Android 轻量级ORM数据库开源框架ActiveAndroid 源码分析
- Requirements of children
- codecomb 2086【滑板鞋】
- Windows phone 8 学习笔记(2) 数据文件操作
- 学习axios
- Django中怎么做图片上传--图片展示
- Ubuntu 安装 OpenMPI
- C# 获取文件名及扩展名【转】
- iOS变量定义在 .h 还是 .m 中
- vue学习之node.js
- 学号20155308 2016-2017-2 《Java程序设计》第5周学习总结
- 机器学习(6): 层次聚类 hierarchical clustering
- HEVC 有损优化一
- RegExp使用技巧
- 网页实现插入图片—css与html的区别