我面臨以下問題:在有訂單記錄的表中,我想在特定位置插入新記錄或將記錄複製/移動到另一個位置。Yii2錯誤的路線,如控制器/控制器/行動
在索引視圖中,我在網格視圖中定義了其他操作按鈕{new} {copy} {move}。點擊其中一個路由到一個名爲select(controller/select)的新視圖,該視圖只有兩個操作按鈕{before} {after},表示該記錄是放置在上面還是下面選定的記錄。
點擊其中一個按鈕路由到控制器動作創建(如果以前被選中爲新建)或控制器動作複製移動(控制器/創建或控制器/複製移動)。控制器完成他的工作,並用$ this-> redirect(['index'])返回索引視圖。這工作正常。
再次點擊索引視圖{新} {複製} {移動}中的一個動作按鈕我看到一個奇怪的路線:控制器/控制器/選擇,而不是控制器/選擇。此行爲僅在我通過刷新瀏覽器從菜單調用索引視圖時纔會停止。
爲什麼會發生這種情況?這可能是因爲之前在網格視圖中選擇操作後立即創建網格視圖?以及如何避免這種行爲?
這是工作流程:
call index view
click on action button {new} {copy} or {move}
create route controller/select
get the select view
in select view click on action button {before} or {after}
create route controller/copy or controller/copy-move
create a new record at the choosen position or copy/move it there
return $this->redirect(['index']) after controller has done his job
in index view again click onto action button {new} {copy} or {move}
create route controller/controller/select instead of controller/select which ends in a 404 error.
如何生成到'controller/select'的鏈接? – gmc
它在index.php中生成 - 在index.php中: – chrisly49
@gmc其生成如此: 'before'=> function($ url,$ model){ $ session = Yii :: $ app-> session; $ mode = $ session ['mode']; $ url =($ mode ==='create')? 'create?idTo =':'copy-move?idTo ='; return Html :: a(''.FA :: icon('upload')。'', $ url。$ model ['id']。'&position = before', ['title'=> '標題')]); – chrisly49