简体   繁体   English

流明 - 带前缀和可选参数的路由

[英]Lumen - Routing with Prefix and Optional Parameter

I'm looking at routing in Lumen and it doesn't appear to be working correctly and I can't work out if it's an issue or my understanding. 我正在看Lumen中的路由,它似乎没有正常工作,如果这是一个问题或我的理解,我无法解决。

$router->get('{adaptor}[/{id}]',     ['uses' => 'MyController@readAction']);

This way works, but I'd prefer to use a prefix to group all my routes: 这种方式有效,但我更喜欢使用前缀来分组我的所有路由:

$router->group(['prefix' => '{adaptor}'], function () use ($router) {
        $router->get('[/{id}]',      ['uses' => 'MyController@readAction']);
       // CRUD routes to be added here
});

If I go to /acme I get MethodNotAllowed Exception, but if I add /acme/1 it works fine. 如果我去/acme我得到MethodNotAllowed异常,但如果我添加/acme/1它工作正常。 Does a prefix NEED another route item for it to work? 前缀是否需要另一个路由项才能工作?

A prefix will need another route item in order for it to work correctly. 前缀需要另一个路由项才能正常工作。

https://lumen.laravel.com/docs/5.4/routing#route-parameters https://lumen.laravel.com/docs/5.4/routing#route-parameters

Optional parameters are only supported in a trailing position of the URI. 可选参数仅在URI的尾随位置受支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM