Reputation: 35
I'm facing the following problem: In a table with ordered records I want to insert a new record at a specific location or copy / move a record to another position.
In the index view I defined the additional action buttons {new} {copy} {move} in the grid view. A click onto one of them routes to a new view called select (controller/select) with a grid view of the same table with only two action buttons, {before} {after}, indicating whether the record should be placed above or below the selected record.
Clicking on one of these buttons routes to the controller action create (if formerly was selected new) or the controller action copy-move (controller/create or controller/copy-move). The controller does his job and returns to the index view with $this->redirect(['index']). This works properly.
Clicking again onto one of the action buttons in index view {new} {copy} {move} I see a strange route: controller/controller/select instead of controller/select. This behaviour stops only when I call the index view from the menu it doesn't by refreshing the browser.
Why does this happen? Is it maybe because of immediatly creating a grid view after selecting an action in a grid view before? And how to avoid this behaviour?
This is the work-flow:
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.
Upvotes: 1
Views: 378
Reputation: 2258
You are facing problem with relative and absolute urls. In yii2
// relative route: /index.php?r=admin%2Fpost%2Findex
echo Url::to(['post/index']);
// absolute route: /index.php?r=post%2Findex
echo Url::to(['/post/index']);
NOTE:- forward slash is required
For more information see this
Upvotes: 3
Reputation: 35
Looks like I got the answer to my question. I removed all logic from the view file defining a specific action with it's route letting kartik grid view generate the url in the action section of columns. So in index.php I have three actions with an own route for each: {new} routes to new, {copy} routes to copy and {move} routes to move.
Then I did the same for select.php where the actions are {before} routing to before and {after} routing to after.
In the controller, the routes then are redirected to select action in the first case and to create action resp. copy-move action in the second case.
This seams to work properly and I don't get that wrong route anymore.
Thanks for helping.
Upvotes: 0