0

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?

topher
  • 14,790
  • 7
  • 54
  • 70
phpdev
  • 511
  • 4
  • 22

1 Answers1

1

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"],
topher
  • 14,790
  • 7
  • 54
  • 70
  • Could you show the result of `var_dump($model->json);` – topher Jan 09 '17 at 09:30
  • Insead of value of decoded json, it is showing this message – phpdev Jan 09 '17 at 09:30
  • string(4018) "{"Block":{"name":"block","view":"pdf\block","p_1":"SSP ","p_2":"\u0410\u043a\u0446\u0438\u043e\u043d\u0435\u0440\u043d\u043e\u0435 \u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e","p_3":"123456789","p_4":"12345","p_5":"12345","p_6":["3","12"],"p_7":"\u0410\u0421 - 3185515", ...... – phpdev Jan 09 '17 at 09:33
  • And `var_dump(CJSON::decode($model->json)["Block"]["p_1"])`? – topher Jan 09 '17 at 09:38
  • string(3) "SSP" – phpdev Jan 09 '17 at 09:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132680/discussion-between-topher-and-phpdev). – topher Jan 09 '17 at 09:59