Hi Im using CgridView with CSqlProvider with it
here is my controller file action index:
public function actionIndex()
{
$connection=Yii::app()->db;
$sql="SELECT empid, firstname, middlename, lastname, title, course FROM Students";
$rowcountsql = "SELECT COUNT(*) FROM Students";
$command = $connection->createCommand($rowcountsql);
$count=$command->queryScalar(); // provide count for pagination
// create data provider that works with CGridView
$dataProvider=new CSqlDataProvider($sql, array(
‘totalItemCount’=>$count,
‘pagination’=>array(
‘pageSize’=>5,
),
));
$this->render(‘index’,array(‘dataProvider’=>$dataProvider
));
}
My index view file:
<?php
$this->widget(‘zii.widgets.grid.CGridView’, array(
‘id’=>‘customer-address-grid’,
‘dataProvider’=>$dataProvider,
‘enablePagination’=>true,
‘ajaxUpdate’=>true,
‘enableSorting’=>true,
‘columns’=>array(
‘firstname:html:First Name’,
‘lastname:html:Last Name’,
‘middlename:html:middlename’,
‘lastname:html:lastname’,
‘title:html:title’,
‘course:html:course’
),
)); ?>
and after that I received an error;
PHP notice
Undefined index: id
/var/www/YiiProject2/yii/framework/web/CSqlDataProvider.php(119)