【问题标题】:F3: Rerouting to a dynamic URLF3:重新路由到动态 URL
【发布时间】:2017-05-25 18:40:07
【问题描述】:

我在从控制器内重新路由到动态 URL 时遇到了一些困难。

在 routes.ini 中

GET /admin/profiles/patient/@patientId/insert-report = Admin->createReport

在控制器 Admin.php 中,在方法 createReport() 中:

$patientId = $f3->get('PARAMS.patientId');

我的尝试(在 Admin.php 中):

$f3->reroute('admin/profiles/patient/' . echo (string)$patientId . '/insert-report');

问题:如何重新路由到相同的 URL(将显示一些错误消息)而不 完全改变路由,即附加 patientId 作为 URL 查询参数?

谢谢,K。

【问题讨论】:

    标签: dynamic parameters fat-free-framework reroute


    【解决方案1】:

    连接字符串不需要echo 语句:

    $f3->reroute('admin/profiles/patient/' . $patientId . '/insert-report');
    

    以下是获得相同结果的其他 3 种方法:

    1) 从当前模式构建 URL

    (用于重新路由到具有不同参数的同一路由)

    // controller
    $url=$f3->build($f3->PATTERN,['patientId'=>$patientId]);
    $f3->reroute($url);
    

    2) 重新路由到相同的模式、相同的参数

    (用于从 POST/PUT/DELETE 重新路由到相同 URL 的 GET)

    // controller
    $f3->reroute();
    

    3) 从命名路由构建 URL

    (对于重新路由到不同的路线很有用)

    ;config file
    GET @create_report: /admin/profiles/patient/@patientId/insert-report = Admin->createReport
    
    // controller
    $url=$f3->alias('create_report',['patientId'=>$patientId']);
    $f3->reroute($url);
    

    或简写语法:

    // controller
    $f3->reroute(['create_report',['patientId'=>$patientId']]);
    

    【讨论】:

      猜你喜欢
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      相关资源
      最近更新 更多