Make CSqlDataProvider in Yiiframework

You can make easily CSqlDataProvider

Step – 1

Write a function into your controller (Like below function)

  1. public function actionAllCarerConfirmed(){
  2.         $sql =’SELECT*from tbl_name’;
  3.         $countSql = ‘SELECT COUNT(*) from tbl_name’;
  4.         $count = Yii::app()->db->createCommand($countSql)->queryScalar();
  5.         $dataProvider = new CSqlDataProvider($sql, array(
  6.             ‘totalItemCount’ => $count,
  7.             ‘sort’ => array(
  8.                 ‘attributes’ => array(
  9.                     ‘column_1′,‘column_2′
  10.                 ),
  11.             ),
  12.             ‘pagination’ => array(
  13.                 ‘pageSize’ => 50,
  14.             ),
  15.         ));
  16.         // $dataProvider->getData() will return a list of arrays.
  17.         $this->render(‘allCarerConfirmed’, array(
  18.             ‘dataProvider’ => $dataProvider,
  19.         ));
  20.     }

 

Step – 2

Call CGridView Widget into your view file

  1. $this->widget(‘zii.widgets.grid.CGridView’, array(
  2.                 ‘id’ => ‘carer-response-grid’,
  3.                 ‘dataProvider’ => $dataProvider,
  4.                 ‘columns’ => array(
  5.                     ‘column_1′,
  6.                     ‘column_1′,
  7. ),
  8. ));

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>