F3:重新路由到动态URL

时间:2017-05-25 18:40:07

标签: dynamic parameters fat-free-framework reroute

我在控制器中重新路由到动态网址时遇到了一些困难。

在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。

1 个答案:

答案 0 :(得分:2)

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

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

以下是另外三种获得相同结果的方法:

1)从当前模式构建网址

(对于使用不同参数重新路由到相同路线非常有用)

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

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

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

// controller
$f3->reroute();

3)从命名路线构建网址

(用于重新路由到其他路线)

;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']]);
相关问题