Slim 3 - 如何在路线中添加或选择?
Slim 3 - how add or-option into the route?
如何在 Slim 3 routes 中添加 or-option?
例如,这是我目前所做的:
// Home page.
$app->get('/', function (Request $request, Response $response, array $args) {
// Get the application settings.
$settings = $this->get('settings');
// Check if the home page class is provided.
... lots of codes
});
$app->get('/home', function (Request $request, Response $response, array $args) {
// Get the application settings.
$settings = $this->get('settings');
// Check if the home page class is provided.
... lots of codes
});
我可以不重复这些代码块,而是把它们变成这样的代码:
$app->get('/ or /home', function (Request $request, Response $response, array $args) {
...}
Optional segments 就是您要找的。
如何在 Slim 3 routes 中添加 or-option?
例如,这是我目前所做的:
// Home page.
$app->get('/', function (Request $request, Response $response, array $args) {
// Get the application settings.
$settings = $this->get('settings');
// Check if the home page class is provided.
... lots of codes
});
$app->get('/home', function (Request $request, Response $response, array $args) {
// Get the application settings.
$settings = $this->get('settings');
// Check if the home page class is provided.
... lots of codes
});
我可以不重复这些代码块,而是把它们变成这样的代码:
$app->get('/ or /home', function (Request $request, Response $response, array $args) {
...}
Optional segments 就是您要找的。