Call a database-function in CGridview

Hello everyone,

is it possible to call a user-defined database function in CGridview?

I tried it like this but the page only renders to this line of code, it then stops.




array(

   		'header' => 'test',

      		'value'=>'computeTIME(time, code, 1, 16)',

   		),



Any Ideas?

You could use a Helper static function like this.




'value' => 'CGridHelper::computeTIME($data->time, $data->code, 1, 16)',



Put the helper class in /protected/helpers/




<?php


class CGridHelper {

   public static function computeTIME($time, $code, 1, 16) {

      ...

   }

}



And don’t forget to import helpers in config/main.php




...

'import'=>array(

    ...

    'application.helpers.*',

    ...

)

...



I was probably unclear but what I really ment was how I can call a databasefunction in CGridview, like MYSQLs NOW(). Or maybe it’s the same way?

Thanks for the answer tho, was another question I was planning to ask in the forum :rolleyes:

I am also facing the problem regarding the cGrid View

I have two different column and both had a id came from different table and i want to display

their name instead of id’s. so i want to run query in that column how can i do that…

					&#036;this-&gt;widget('zii.widgets.grid.CGridView', array(


							'dataProvider'=&gt;&#036;dataProvider,


							'columns'=&gt;array(


						array(


							'name' =&gt; 'id',


							'type'=&gt;'raw',


							'value' =&gt;'&#036;data[&quot;id&quot;]',


							),


						array(


							'name' =&gt; 'Activity Name',

‘value’ =>‘modelclassname::functionname($data->time, $data->code, 1, 16)’,//this line is not working for me

						),


						array(


							'name' =&gt; 'Prodcut Name',


							'value' =&gt; '&#036;data[&quot;product_id&quot;]',


						),	


						 	array(


						  'class'=&gt;'CButtonColumn',


						  'template'=&gt;'{update}{delete}',


						   'deleteButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;HairJournal/HairJournal/deleteactivityproduct&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


						   'updateButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;HairJournal/HairJournal/updateactivityproduct&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


						  'deleteConfirmation'=&gt;&quot;js:'Do you really want to delete record with ID '+&#036;(this).parent().parent().children(':nth-child(2)').text()+'?'&quot;,


						),


		


					),


				));