view of grid view
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$dataProviderObj,
'columns'=>array(
'productName',
'productType',
'productBrand',
'description',
array(
'name' => '<column_name>'
'value' => array($this,'gridCreateduser')
)
),
));
This is you grid view value => array($this,'gridCreatedUser')
this means that grid view will search a function in its controller for a function gridCreateUser()
Now in controller
public function gridCreateUser($data,$row){
$user = $data-><colmn_name>;
//do your stuff for finding the username or name with $user
//for eg.
$detail = User::model()->findByPk($user);
// make sure what ever model you are calling is accessible from this controller other wise you have to import the model on top of the controller above class of the controller.
return $detail->username;
}
No this will send the desired value of that coulmn name to grid view.
Or you can use in a simple manner by defining relation between models inside model whose gridview you are creating
public function relations(){
return array(
'users' => array(self::HAS_MANY, 'Users', '<column_name>'),
);
}
Then you can directly access it in you grid view
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$dataProviderObj,
'columns'=>array(
'productName',
'productType',
'productBrand',
'description',
array(
'name' => '<column_name>'
'value' => $data->users->username
)
),
));