douna1895 2019-06-25 23:03
浏览 64
已采纳

如何在Lazy Loading方式中使用联盟/路线中的通配路线

I am using league/route 4.2. I am trying to implement a lazy loading controller using wildcard.

class Router
{
    private $container;
    private $router;

    function __construct()
    {
        $this->container = new Container();
        $this->router = new \League\Route\Router();
        $this->mapRouters();
        $this->dispatch();
    }

    private function mapRouters() {
        $this->router->map('GET', '/', [MainController::class, 'index']);
        //$this->router->map('GET', 'Main', 'Nanitelink\Module\Main\MainController::index');
        $this->router->map('GET', '{module}', 'Nanitelink\Module\{module}\{module}Controller::index');
    }

    private function dispatch() {
        $request = $this->container->get('Zend\Diactoros\ServerRequest');
        $response = $this->router->dispatch($request);
        $emitter = $this->container->get('Zend\HttpHandlerRunner\Emitter\SapiEmitter');
        $emitter->emit($response);
    }
}

Now I know for a fact that the commented route works. I tried to replace it with wildcard, but probably I am not getting the syntax correctly, but it throws following exception.

Class 'Nanitelink\Module\{module}\{module}Controller' not found

What is the right way to use wildcard routing in league/route? Documentation does not explain how to use wildcard in lazy loading way.

  • 写回答

1条回答 默认 最新

  • dongshao8471 2019-06-27 01:49
    关注

    This was the discussion on github with the package manager.

    https://github.com/thephpleague/route/issues/247

    So to keep the answer short, the package does not and will not allow the requirement to replace the callable to be named using variables matched to the wildcard.

    I did suggest a source code change in github, if anyone need the information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)