duanliang9288 2017-05-03 07:13 采纳率: 100%
浏览 7
已采纳

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

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?

  • 写回答

1条回答 默认 最新

  • dongxiaoying5882 2017-05-03 08:06
    关注

    @Tobia i hope want to this(for slim framework 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()

    A route can tell the Slim application to continue to the next matching route with the Slim application's pass() method

    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){
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题