-2

i want to insert value through Json_encode through controller but json_encode() not working in yii2.

json_encode();
Priya
  • 1
  • 4

1 Answers1

0

You can test json_encode() in a controller:

public function actionIndex()
{
    $json = json_encode(['key'=>'value']);
    echo $json;
}

The result should be:

{"key":"value"}

json_encode() won't be unworked without an error such as no php-json extension, and it is a PHP function which works the same in Yii2.

Nick Tsai
  • 2,961
  • 28
  • 32