h3rm
July 19, 2011, 3:40pm
1
Hi… i have problem, about view button url an CButtonColumn - CGridView.
i use CSQLDataprovider to get data from sql.
this my gridview code:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model,
'pager'=>array('class'=>'CLinkPager'),
'enableSorting'=>true,
'columns'=>array(
'customer_id',
'firstname::First Name' ,
),
array(
'class'=>'CButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/account/view",array("id"=>$data->customer_id))',
'viewButtonLabel'=>'Show Data',
),
my problem in this line:
'viewButtonUrl'=>'Yii::app()->createUrl("/account/view",array("id"=>$data->customer_id))',
because, id at account.view not get value from field database: $data->customer_id
the result of url is:
http://localhost/yii/lat/testdrive/index.php/account/view/id
i want url to be:
http://localhost/yii/lat/testdrive/index.php/account/view/id/34
This works well if using CActiveDataProvider but not with CSqlDataProvider
mdomba
(Maurizio Domba Cerin)
July 19, 2011, 7:50pm
2
But do you see the value of customer_id in the first column ?
In the code you have
'dataprovider'=>$model,
generaly here is something like
'dataprovider'=>$model->search(),
and search() is a method that returns an CActiveDataProvider… so in your case it would return CSqlDataProvider…
h3rm
July 20, 2011, 1:35am
3
yes, is see customer_id in first column.
this is $model code:
$sql ="select * From customer order by firstname,lastname";
$count = Yii::app()->db->createCommand('select COUNT(*) from customer')->queryScalar();
$model= new CSqlDataProvider($sql,array(
'totalItemCount'=>$count,
'pagination'=>array('pageSize'=>10),
'sort'=>array(
'attributes'=>array(
'firstname','lastname','email'
),
),
)
);
does not work
h3rm
July 20, 2011, 2:06am
4
ok done,
i replace this line:
$data['customer_id'];
so, my questions is, why is there a difference when render data to CGridView, between CSqlDataProvider and CActiveDataProvider. whether this was made like this ?
mdomba
(Maurizio Domba Cerin)
July 20, 2011, 6:12am
5
Great you found that out… I completely forgot it… as the doc say (http://www.yiiframew …SqlDataProvider):
while CActiveDataProvider as the doc say (http://www.yiiframew …iveDataProvider):
h3rm
July 20, 2011, 6:30am
6
thank you, i can see in this note:
and