[英]Slim route order declaration and route parameter
I have many routes declared in my slim application. 我在细长型应用程序中声明了许多路由。 Some of these have route parameters
其中一些具有路由参数
$app->get("/:user/profile",function($user) use($app){ ... });
$app->get("/test/:id",function($id) use($app){ ... });
For example if I call: 例如,如果我打电话:
http://myhost/test/1
It is suitable for both routes, then the declaration order is very important! 这两种路线都适用,那么声明顺序非常重要! Is there any way to give priority to static router from parametrized?
有什么方法可以将静态路由器的优先级设置为参数化?
@Tobia i hope want to this(for slim framework 2): @Tobia我希望这样(对于苗条框架2):
whenever if you have two routes in a file and you think that your two routes can be same URI at the time of calling So in that case use pass()
每当文件中有两条路由并且您认为在调用时两条路由可以是相同的URI时,在这种情况下请使用
pass()
A route can tell the Slim application to continue to the next matching route with the Slim application's pass() method
路由可以通过Slim应用程序的pass()方法告诉Slim应用程序继续到下一个匹配的路由
for your above case make some condition, try this like: 对于上述情况,请进行以下操作:
$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){
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.