Farhad
Farhad

Reputation: 85

How to use $model-> attribute inside 'value' of CGridView

This is my index

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'tblvehicleimagegrid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
      'serial_no',
    array(

      'header'  =>'image',
        'type'=>'image',

       'value'=>'Yii::app()->baseUrl."/images/originals/".$model->serial_no."img/img". $model->line_no.".jpg"',


      ),

The $model is not recognized inside the value because of the single quotation mark maybe. ANd without the mark no image is shown. Can anyone give an idea , how can i overcome this?

Upvotes: 0

Views: 114

Answers (2)

Let me see
Let me see

Reputation: 5094

try using this

$data->attribute

or $data->serial_no in your case
So your value becomes

'value'=>'Yii::app()->baseUrl."/images/originals/".$data->serial_no."img/img". $data->line_no.".jpg"',

Note:-
$data is an object that stores the values related to your current record.
The single quotes are not the problem. You have to wrap it inside single quote only.

Upvotes: 1

naveen goyal
naveen goyal

Reputation: 4629

Use $data instead of model ...Try this In GridView you can access model by using $data->attribute.

'value'=>'Yii::app()->baseUrl."/images/originals/".$data->serial_no."img/img". $data->line_no.".jpg"',

Upvotes: 0

Related Questions