How to decode json data in CDetailView in yii 1

307 Views Asked by At

I have following code in my view:

<?php $this->widget('zii.widgets.CDetailView', array(
    'data' => $model,
    'attributes' => array(
        'id',
        'name',
        array(
            'label' => 'Company',
            'type'  => 'raw',
            'value' => 'CJSON::decode($data->json)["Block"]["p_1"]',
        ),
    ),
)); ?>

I have field called json in my database. This field contains json formatted data. I used following code in order to decode json data:

array(  'label' => 'Company',
        'type'=>'raw',
        'value' =>'CJSON::decode($data->json)["Block"]["p_1"]',
),

When I used this json decoding code in CGridView it worked and returned desired value. However, when I used this code in CDetailView, it did not work. The widget returned this code CJSON::decode($data->json)["Block"]["p_1"] instead of decoded data. How can I decode json data in CDetailView?

1

There are 1 best solutions below

6
topher On BEST ANSWER

There is no need to pass a string as the value for CDetailView. As such you can just use:

'value' => CJSON::decode($model->json)["Block"]["p_1"],