ID in gridview ActionColumn

In one Index I have this:


        	'class' => 'yii\grid\ActionColumn',

       			'template' => '{view}{update}{delete}',

				'header' => 'Azioni',

				'visible' => (Yii::$app->user->can("admin")),

				'options' => ['width' => '120'],


Don’t ask me why, but I changed in my related table the auto_increment field fron “ID” to “IDX”. Obviously I changed all related reference in every view, controller, search. But for some reason, in index view were are a gridview and relative buttons, they still pointing to old /right_controller/right_action/?WRONG_ID=right_real_id.

Where I must looking for to change ID to IDX in ActionColumn buttons?

Have you changed primary key in db’s table?

Yes, unfortunately I had to do it

Seeing ActionColumn.php in createUrl there is:

             $params = is_array($key) ? $key : ['id' => (string) $key];

seems that ‘id’ is typed in code.

I think that solution could be:

  1. Keep id in controller action and change loadModel content, loading data using ‘idx’ and not ‘id’ (but considering id value);

  2. Specify a closure function in generating every single action (update, view, delete) in ActionColumn;

I’ll use first solution.

I think your solution is above my chances, but the problem arises because I need to copy values from one table to another, and for this I use this code:

$model2->setAttributes($model1->getAttributes(), false);

If I was able to copy field by field from one table to another, I could copy the primary ID of the first table into the second one. So also the ID of the second one it will be which name like I wish, and I will leave Id of second one primary and alone. I do not know if I was clear enough …

Try with:

for($model1->attributes as $k=>$v)


     $model2->setAttribute($k, $v);


If you neeed also to leave ‘id’ of second table

for($model1->attributes as $k=>$v)


     if($k=='id') continue;

     $model2->setAttribute($k, $v);


Thank you. I will try twice your solution. The first one is more quickly, and seems working (for the moment only for view action, but I must work also for delete and so on), but the second one I think it will more definitive, and clear.

Yes, this was the right way. I messed with the keyword "ID" and the value. Now it works. Thank you again, you drive me in the right direction.