Slim 路由顺序声明和路由参数
Slim route order declaration and route parameter
我在我的 slim 应用程序中声明了很多路由。
其中一些有路由参数
$app->get("/:user/profile",function($user) use($app){ ... });
$app->get("/test/:id",function($id) use($app){ ... });
例如,如果我调用:
http://myhost/test/1
两条航线都适合,那么报关顺序很重要!
有什么办法可以优先考虑参数化的静态路由器?
@Tobia 我希望这样(对于 slim framework 2):
每当你在一个文件中有两个路由并且你认为你的两个路由在调用时可以是相同的 URI 所以在这种情况下使用 pass()
A route can tell the Slim application to continue to the next matching
route with the Slim application's pass() method
针对您的上述情况,提出一些条件,试试这样:
$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){
});
我在我的 slim 应用程序中声明了很多路由。 其中一些有路由参数
$app->get("/:user/profile",function($user) use($app){ ... });
$app->get("/test/:id",function($id) use($app){ ... });
例如,如果我调用:
http://myhost/test/1
两条航线都适合,那么报关顺序很重要! 有什么办法可以优先考虑参数化的静态路由器?
@Tobia 我希望这样(对于 slim framework 2):
每当你在一个文件中有两个路由并且你认为你的两个路由在调用时可以是相同的 URI 所以在这种情况下使用 pass()
A route can tell the Slim application to continue to the next matching route with the Slim application's pass() method
针对您的上述情况,提出一些条件,试试这样:
$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){
});