问题
I have a route like this:
$routes->connect('/custom/url', [
'prefix' => 'admin', 'controller' => 'Things', 'action' => 'index'
]);
I want to allow an optional passed parameter so the URL can be /custom/url/123
but also still allow it to not have the parameter at all, like /custom/url
.
If I change the route to /custom/url/:param
it throws an exception if I visit the URL without the extra parameter. How can I make the parameter matching lazy?
回答1:
routes like:
$routes->connect('/custom/url/*', [
'prefix' => 'admin', 'controller' => 'Things', 'action' => 'index'
]);
In controller
public function index($param = null){
// your code here
}
来源:https://stackoverflow.com/questions/37448765/cakephp-3-configure-route-to-allow-optional-parameter