zoukankan      html  css  js  c++  java
  • lumen怎么得到当前Uri的控制器、Action、路由规则

    <?php
    
    namespace AppHttpControllers;
    
    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'])); } }
  • 相关阅读:
    014_Python3 循环语句
    013_Python3 条件控制
    012_Python3 斐波纳契数列 + end 关键字
    011_Python3 集合
    010_Python3 字典
    009_Python3 元组
    008_Python3 列表
    006_Python3 数字(Number)
    005_Python3 运算符
    bzoj3160
  • 原文地址:https://www.cnblogs.com/dongruiha/p/6956866.html
Copyright © 2011-2022 走看看