【问题标题】:Slim 3 - how add or-option into the route?Slim 3 - 如何在路由中添加或选项?
【发布时间】:2016-04-07 17:16:00
【问题描述】:

我如何在Slim 3 routes 中有或选项?

例如,这是我目前所做的:

// 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不是你想要的吗?
  • 是的!谢谢!
  • @EvgenySoynov 请添加您的评论作为答案。然后OP可以接受它。

标签: routes slim slim-3


【解决方案1】:

Optional segments 就是你要找的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多