I have functions for work with database in one of my controllers. Something like this:
static function getCamByClassId($id)
{
$connection=Yii::app()->db;
$command=$connection->createCommand("some query");
$camReader=$command->query();
$camList=$command->queryAll();
return $camList;
}
Also I'm using zii widget. Like this:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'someId',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name' => 'Image',
'type' => 'raw',
'value' => 'CHtml::image("/uploads/thumb_".$data->Lesson_ID."_".$data->Image, "" ,array(\'width\'=>195, \'height\'=>110))',
,
),
...
),));
Now I need to use other pictures there, that I get with help of this method.
I tried to replace 'value'
property on
'value' => 'CHtml::image(".$this->getCamByClassId($data->Lesson_ID)[0][\'Cam1\'].", "default image" ,array(\'width\'=>195, \'height\'=>110))',
And then I receive this exception:
Property "CDataColumn.getCamByClassId" is not defined.
There is no sense as I see to copy method into CDataColumn.php, because it looks for property and I can't set method return value to some property of this calss because it's result depends on $id
parameter. How get I pass to 'value' property result of getCamByClassId?
UPDATE
Ok, I can use it like LessonController::getCamByClassId
, but how can I pass $data->LessonId
then?
UPDATE1
tried this
'value' => 'CHtml::image(".$this->grid->controller->getCamByClassId($data->Lesson_ID).", "default image" ,array(\'width\'=>195, \'height\'=>110))',
It says: Object of class CGridView could not be converted to string UPDATE2 Checked last suggestion of topher
'value' => function($data, $row) {
return CHtml::image(
LessonController::getCamByClassId($data->Lesson_ID)[0]['Cam1'],
"default image",
array('width'=>195, 'height'=>110)
);
}
My mistake: I had a typo. Now it says that 0 is undefined offset, gonna debug it.