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.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测