CGridView CButtonColumn - Chanding the URL Parameter


The default Admin View shows a data grid, and each row has a VIEW / UPDATE / DELETE button.

I’ve recently changed my Primary Key, so for the Table concerned, its no longer ‘ID’ its now ‘ID_LEAD’…

So if you click UPDATE, it tries to load


But i need it to load


I’ve experimented with changing the CButtonColumn in the Admin View:







				'update' => array






It shows the URL:


but I dont know how to get the value of ‘id_lead’ in there… also it feels abit too clunky to do this…

Can this be set sitewide - im guessing, its built into the Framework, and i obviously dont want to hack that…


ok, i added this, and the URL works now, but there must be a better way…







      'update' => array


        'url'=>'$this->grid->controller->createUrl("/leads/update", array("id_lead"=>$data->primaryKey))',





You can use

'url'=>'CController::createUrl("/leads/update", array("id_lead"=>$data->primaryKey))'

EDIT: As the button column evals the code you really have to give it a string. So use CController to create the url. That should work

Hi ThePaulius

If it can help you the default url are set in this line:

         * @var string a PHP expression that is evaluated for every update button and whose result is used

         * as the URL for the update button. In this expression, the variable

         * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;

         * and <code>$this</code> the column object.


        public $updateButtonUrl='Yii::app()->controller->createUrl("update",array("id"=>$data->primaryKey))';

So, you need to configure it manually.

There is however another solution!:)

I was wondering why I never have met this problem. The reason is that I use User-friendly URLs . So that is a way to make the buttons create a valid url even if you changed the name of primaryKey. But I think the User Friendly Urls are good to use for other reasons as well, and quite easy to implement. See the link.

Good Luck

Nice thank you, that worked, shorter too.

Great thank you for finding were id= is created, i am very tempted to change it, but i wont because i know when i update the framework, i will forget that i changed that! lol

Also, thanks for the tip on friendly URLS, I guess that will fix the problem for sure. I do prefer friendly URLS (Hate ?id=xyz …) I tried creating them early in the project, but reverted back becasue all urls still had index.php? which is really weird. I think I tried out something with htaccess rewrites, but gave up.



Hi i m trying to do the same but a got the error notice "Trying to get property of non-object" even when i m takin off all the attributes of CButtonColumn.

If i take off the CButtonColumn array of the CGridView this is shown well (without the options of course).

the dataProvider is created with a CSqlDataProvider with a custimized quuery with a join with 2 tables, its possibly that result dont match with any model in the system and,this could be the error but, this can be fixed?

code the model

public static function myData($id = '' )



		$count=Yii::app()->db->createCommand('SELECT COUNT(xx)

				FROM rr AS cs

				INNER JOIN zz AS c ON = cs.rr_id

				WHERE cs.hh_id =\''.$id.'\'')->queryScalar();

		$sql='SELECT, aa, bb, cc

				FROM rr AS cs

				INNER JOIN zz AS c ON = cs.rr_id

				WHERE cs.hh_id =\''.$id.'\'';

		$dataProvider=new CSqlDataProvider($sql, array(




								'id', 'aa', 'bb','cc',







		return $dataProvider;

		// $dataProvider->getData() will return a list of arrays.


code de view

<?php $this->widget('zii.widgets.grid.CGridView', array(