Jump to content
Larry Ullman's Book Forums

Yii Cgridview How To Access Id For Each Column

Recommended Posts

I am using a CGridView with CActiveDataProvider. Everything works fine however now I have a need to show a custom button depending upon the id of the row.

I can add the button and get it to work as well however I cannot customise the image according to the row id. I can see from examples that when creating url I can access the id of row by calling $data->id however when I try to do that for imageURL it does not work. My code is below:

$this->widget('zii.widgets.grid.CGridView', array(
						'header'=>'Active State',
										'url'=>'Yii::app()->createUrl("users/updateRank", array("id"=>$data->id))',

Image URL calls a function in my controller which returns a url to the image. However I cannot pass the id of the current record user is clicking upon and I always get the default image back. If I use $data->id I get an error that data does not exist. If I use $this->id it is referring to the controller and I get the controller id. Anyway I can get the id of the row and pass it over to a function.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...