CakePHP 3 - 配置路由以允许可选参数

3

我有如下这样的路由:

$routes->connect('/custom/url', [
    'prefix' => 'admin', 'controller' => 'Things', 'action' => 'index'
]);

我希望允许可选的传递参数,使URL可以是/custom/url/123,但仍然允许没有参数,例如/custom/url
如果我将路由更改为/custom/url/:param,则在不带额外参数访问URL时会抛出异常。如何使参数匹配惰性?
1个回答

4

路由如下:

$routes->connect('/custom/url/*', [
    'prefix' => 'admin', 'controller' => 'Things', 'action' => 'index'
]);

在控制器中

public function index($param = null){
  // your code here
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接