How to call decoded json field values in view in yii 1

188 Views Asked by At

I have following code in my controller:

$model=ChForms::model()->findByPk($id);
$decode= $model->json;
$res=CJSON::decode($decode);
var_dump($res);
return $this->render('index', array('model'=>$model, 'res'=>$res));

the result of var_dump($res) is:

["p_2"]=> string(4) "test" ["p_3"]=> string(1) "0" 

How can I call values of ["p_2"] and ["p_3"] in my view(e.g test, 0)

1

There are 1 best solutions below

0
topher On

CJSON::decode() returns an array by default. Since you are passing $res into your view you can access the required fields via $res["p_2"] and $res["p_3"].