细长的路线订单声明和路线参数

时间:2017-05-03 07:13:19

标签: php slim

我的瘦身应用程序中声明了很多路径。 其中一些有路由参数

$app->get("/:user/profile",function($user) use($app){ ... });
$app->get("/test/:id",function($id) use($app){ ... });

例如,如果我打电话:

http://myhost/test/1

它适合两种路线,那么申报顺序非常重要! 有没有办法优先考虑参数化的静态路由器?

1 个答案:

答案 0 :(得分:0)

@Tobia我希望这个(对于苗条的框架2):

每当你在一个文件中有两条路线并且你认为你的两条路线在调用时可以是相同的URI那么在这种情况下使用pass()

  

路由可以告诉Slim应用程序继续下一个匹配   使用Slim应用程序的pass()方法

对于你的上述情况做出一些条件,试试这样:

$app->get("/:user/profile",function($user) use($app){
    if($user == "POSSIBLE VALUES"){ // make condition that can be found in the $user parameter

    }
    else{
        $app->pass();
    }

});

$app->get("/test/:id",function($id) use($app){

});
相关问题