Yii2控制器 返回 json 格式数据

        Yii::$app->response->format = Response::FORMAT_JSON;
        $data = User::find()->where([])->asArray()->one();
        return ['code'=>200, 'msg'=>'成功','data'=>$data];    

结果 使用ajax 获取的数据 console.log()出来

原文地址:https://www.cnblogs.com/arvin-an/p/10270554.html