lumen怎么得到当前Uri的控制器、Action、路由规则

<?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'])); } }

 

posted on 2017-06-07 14:26  dongruiha  阅读(3185)  评论(0编辑  收藏  举报

导航