id not found in CButtonColumn

Hi… :rolleyes: 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

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…

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

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 ?

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):

thank you, i can see in this note:

and