Php 如何将Yii中的所有数据作为参数中的Json输出

Php 如何将Yii中的所有数据作为参数中的Json输出,php,json,yii,Php,Json,Yii,我正在尝试以json格式获取Yii中的所有数据,我已经阅读了关于这一格式的所有内容,特别是这一格式: 如您所见,下载不起作用 我需要为所有数据自动获取类似WordPress api的内容: 或者这个例子: 它在wordpress/api地址中以json的形式获取所有数据。我需要像wordpress api这样的数据。但是,所有数据是什么?如何将这些数据完全作为json获取 例如,这是我的控制器: 如何做到这一点?在您的函数中,如果希望返回类似JSON的API数据,您应该有如下内容 publi

我正在尝试以json格式获取Yii中的所有数据,我已经阅读了关于这一格式的所有内容,特别是这一格式:

如您所见,下载不起作用

我需要为所有数据自动获取类似WordPress api的内容:

或者这个例子:

它在wordpress/api地址中以json的形式获取所有数据。我需要像wordpress api这样的数据。但是,所有数据是什么?如何将这些数据完全作为json获取

例如,这是我的控制器:


如何做到这一点?

在您的函数中,如果希望返回类似JSON的API数据,您应该有如下内容

public function actionSomeAPI()
{
    $data = GetDataFrom::model()->findAll();

    //... parse the data to reduce it to what you want

    // encode the data as JSON and send it to
    // the client
    echo CJavaScript::jsonEncode($data);

    // since we don't want to render the view,
    // and we already have the data we want sent
    // to the browser, we have to halt Yii here.
    Yii::app()->end();
}

你到底想做什么?你面临什么问题?我需要一个自动api来处理所有的数据,比如wordpress api:但是我不能弄清楚数据是什么?
public function actionSomeAPI()
{
    $data = GetDataFrom::model()->findAll();

    //... parse the data to reduce it to what you want

    // encode the data as JSON and send it to
    // the client
    echo CJavaScript::jsonEncode($data);

    // since we don't want to render the view,
    // and we already have the data we want sent
    // to the browser, we have to halt Yii here.
    Yii::app()->end();
}