简体   繁体   中英

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.

$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. 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

Optional parameters are only supported in a trailing position of the URI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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