Slim3 optional parameter with controller method as callback
Asked Answered
C

1

7

I have route:

$app->get('/admin/login/{status}', 'App\Controller\Admin\AdminController:loginAction')

How do I make {status} parameter optional?

Chamonix answered 20/3, 2016 at 14:2 Comment(0)
O
14

use square brackets:

$app->get('/admin/login[/{status}]', 'App\Controller\Admin\AdminController:loginAction')

See http://www.slimframework.com/docs/objects/router.html#route-placeholders

Origen answered 20/3, 2016 at 14:18 Comment(2)
Thank you. I find it hard to understand why is every aspect of slim3 documentation about function() callback.Chamonix
This is because no one has contributed any other documentation. We welcome pull requests to github.com/slimphp/Slim-Website.Origen

© 2022 - 2024 — McMap. All rights reserved.