2017-05-25 85 views
0

我有一些困難重新路由到我的控制器內的動態網址。F3:重新路由到動態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.

回答

1

,則不需要echo聲明連接字符串:

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

這裏有3分其他的方法來獲得相同的結果:

1)建立網址從當前模式

(用於重新路由到具有不同參數的相同路由R)

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

2)重新路由到相同的圖案,相同的參數

(從POST/PUT重新路由有用/ DELETE得到相同URL的)

// 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']]);