【问题标题】:Handling "ends with" routes in Slim 3 (beta)在 Slim 3(测试版)中处理“以”结尾的路由
【发布时间】:2015-08-28 23:52:18
【问题描述】:

我正在使用 Slim Framework 3(最新测试版)。路由规则已更新,现在扩展了 nikic/FastRoute。

我无法让“结束于”路线正常工作。以下是我的两条路线:

$app->get('/{uri:.*(?:css|js|gif|jpg|jpeg|png)$}', function (){ [...] });
$app->get('/{uri:.*}', function (){ [...] });

根据 FastRoute,我们不能使用正则表达式多匹配块 (),但他们建议使用反向引用块来获得相同的效果:https://github.com/nikic/FastRoute#defining-routes

但是,这不起作用。

我想要做的是做一个包罗万象的路线,专门针对网页资产(图像等)使用不同的路线。

【问题讨论】:

  • 我使用$app->get('/asset/{asset:[a-z]+\.(?:css|js)}', function($req, $res, $args) { 生成资产,但我认为这不是“以”结尾。

标签: regex routes slim


【解决方案1】:

我在 Slim 3 中成功地使用此模式重新路由资产:

'/assets/{file:.+}.{ext:css|js|woff|woff2|ttf}'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多