Show data from table

controller:


	public function actionIndex()

	{

		// renders the view file 'protected/views/site/index.php'

		// using the default layout 'protected/views/layouts/main.php'

		$rawData=  Student::model()->findAll();

 

    // or using: $rawData=User::model()->findAll();

        

                $dataProvider=new CArrayDataProvider($rawData, array(

                    'id'=>'user',

                    'sort'=>array(

                    'attributes'=>array(

                        'id', 'name', 'c_id', 'l_id', 'email'

                        ),

                     ),

                        'pagination'=>array(

                        'pageSize'=>10,         //records display

                      ),

                    ));


                    $this->render('index',array(

                        'dataProvider'=>$dataProvider,

                    ));

    }

Index.php:


<?php

/* @var $this SiteController */


$this->pageTitle=Yii::app()->name;

$this->widget('bootstrap.widgets.TbGridView',array(

    'id'=>'user-info-grid',

    'dataProvider'=>$dataProvider,

        'type'=>'striped bordered condensed',

        'template'=>'{summary}{pager}{items}{pager}',

        'columns'=>array(

        'ID',

        'Name',

        'Course',

        'Book',

        'Email',

    ),

    ));

?>



I have a student model in which student table is there.

But it is not showing data in grid why.

i think i am doing something wrong.

Use attributes names in ‘columns’ array.

hey i want to change the name of attribute like for c_id i want course is it possible with changing the database.

Set the name in model class with attributeLabels method or use details for ‘columns’ array like


'columns' => array(

    array(

        'name' => 'c_id',

        'header' => 'Course',

    ),

)

http://www.yiiframework.com/doc/api/1.1/CGridView#columns-detail

http://www.yiiframework.com/doc/api/1.1/CDataColumn