Using Own Column Names In A Query, Results In Error In Yii

Hello dear Yii community,

I have a problem I can’t figure out by myself,

I am still new to yii,

I try this query in my model


public function getSumar() {


    $oDbConnection = Yii::app()->db;

    $oCommand = $oDbConnection->createCommand("SELECT requester_id,

 SUM(CASE WHEN type_id = 0 THEN hours ELSE 0 END) AS 'Spracovanie dopytu',

 SUM(CASE WHEN type_id = 1 THEN hours ELSE 0 END) AS 'Spracovanie podkladov',

 SUM(CASE WHEN type_id = 2 THEN hours ELSE 0 END) AS 'Ostatne cinnosti'

FROM `tbl_report`

GROUP BY requester_id

UNION

SELECT 'TOTAL',

 SUM(CASE WHEN type_id = 0 THEN hours ELSE 0 END),

 SUM(CASE WHEN type_id = 1 THEN hours ELSE 0 END),

 SUM(CASE WHEN type_id = 2 THEN hours ELSE 0 END)

FROM `tbl_report`

");

    $query = $oCommand->queryAll();

    $dataProvider=new CSqlDataProvider($oCommand, array(

        // 'keyField' => 'requester_id',

    ));




    return $dataProvider;


}

this is in my controller


public function actionSumar()

        {


            $model = new DailyReport('getSumar');

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

                'model'=>$model,

            ));

        }

I have this code in my view


$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$model->getSumar(),

));

and I get this error:

The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.

The error is there because I use custom naming of columns in my query :{

but please, can anyone tell me what to do so it will accept those custom named columns?

[size=2]Hi,[/size]

your problem is not in query…

your problem is cgridview… you have not mentioned any column names … please use below format :)

I hope it will work … cheers

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'curriculam-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	array(


		'name'=&gt;'pgm_title',


		'type'=&gt;'raw',


		'value'=&gt;'CHtml::link(&#036;data-&gt;pgm_title, array(&quot;view&quot;,&quot;id&quot;=&gt;&#036;data-&gt;pgm_id))',


		'htmlOptions'=&gt;array('width'=&gt;'320px'),


	),

[size=2] [/size][size=2]),[/size]

)); ?>

Thanks for you reply chandran!

I tried it this way, but I receive another error

[color="#FF0000"]Property "DailyReport.pgm_title" is not defined.[/color]

what is pgm_title? I cannot find it anywhere.

it also say’s there is error in C:\wamp\www\yii\framework\db\ar\CActiveRecord.php(143)

But I am not using active record for this query, I am using sqlDataProvider

Hi no_it_isnt ! First, type in columns array names of columns which you want to display in grid. For example, just add the columns name which you selected:

[i]‘columns’=>array(

‘requester_id’,

‘total’,

),[/i]