Carraydataprovider Keyfield As Button Id In Cgridview

Hello everybody,

I’m trying to use the keyField I’m setting inside of CArrayDataProvider for an id on a button inside of CGridView. The reason I want to do this is so that I can pass the id value onward in an ajax function.

I’m not sure why CArrayDataProvider is not setting the id field in the array to the keyField, and from there, why I can’t set the button’s id with that value. Any help would be much appreciated, thanks in advance!

Here is how I’m building the array that I’m using as my RAW data:

foreach ($items as $item) {

	$tableRow = array("id"=>$item["Id"], "Organization"=>$item["Organization"], "Roles"=>$item["Roles"]);

	$return_items[] = $tableRow;


Here is the CArrayDataProvider setup I’m using. I noticed that ‘keyField’ is not being given the id value, just the string ‘id’:

$dataProvider=new CArrayDataProvider($return_items, array(












Lastly, here is the CGridView I’m trying to setup in the view. All that appears on the button is the id tag, but no value:

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








			  'value'=>'CHtml::button("Edit Roles", array("data-toggle"=>"modal", "data-target"=>"#roles-modal"))'), 




I asked this question on stack overflow later on in the day as I was not getting any responses here, and I have been given a solution. Please visit the post on StackOverflow to see the answer, you can do so here (would’ve made it an active link, but the forum rules say I can’t since it’s one of my first posts, sorry):