isla
(Swisscom90)
1
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?
norkimo
(Werner Strauch)
2
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.*',
...
)
...
isla
(Swisscom90)
3
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 
anand.n
(Anand Neema2008)
4
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…
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name' => 'id',
'type'=>'raw',
'value' =>'$data["id"]',
),
array(
'name' => 'Activity Name',
‘value’ =>‘modelclassname::functionname($data->time, $data->code, 1, 16)’,//this line is not working for me
),
array(
'name' => 'Prodcut Name',
'value' => '$data["product_id"]',
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}{delete}',
'deleteButtonUrl'=>'Yii::app()->createUrl("HairJournal/HairJournal/deleteactivityproduct", array("id" => $data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("HairJournal/HairJournal/updateactivityproduct", array("id" => $data["id"]))',
'deleteConfirmation'=>"js:'Do you really want to delete record with ID '+$(this).parent().parent().children(':nth-child(2)').text()+'?'",
),
),
));