How to get response as json format(application/json) in yii?

后端 未结 8 980
小鲜肉
小鲜肉 2021-01-30 05:08

How to get response as json format(application/json) in yii?

相关标签:
8条回答
  • 2021-01-30 05:56

    In the controller action that you want to render JSON data, e.g: actionJson()

    public function actionJson(){
        $this->layout=false;
        header('Content-type: application/json');
        echo CJSON::encode($data);
        Yii::app()->end(); // equal to die() or exit() function
    }
    

    See more Yii API

    0 讨论(0)
  • 2021-01-30 05:59
    $this->layout=false;
    header('Content-type: application/json');
    echo CJavaScript::jsonEncode($arr);
    Yii::app()->end(); 
    
    0 讨论(0)
提交回复
热议问题