【发布时间】:2016-03-30 12:34:47
【问题描述】:
正如文档所说:
[[yii\rest\IndexAction|index]]: list resources page by page
响应有视图:
curl -i -H "Accept:application/json" "http://192.168.100.5/index.php/tweets"
HTTP/1.1 200 OK
Date: Wed, 30 Mar 2016 12:10:07 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
X-Pagination-Total-Count: 450
X-Pagination-Page-Count: 23
X-Pagination-Current-Page: 1
X-Pagination-Per-Page: 20
Link: <http://192.168.100.5/tweets?page=1>; rel=self, <http://192.168.100.5/tweets?page=2>; rel=next, <http://192.168.100.5/tweets?page=23>; rel=last
Content-Length: 4305
Content-Type: application/json; charset=UTF-8
[{"id":71,"text":"Juíza do RS Graziela Bünd.......
我有一个返回的组件 - 一些数组(从两个表中选择)。如果我自定义 indexAction.
public function actions()
{
$actions = parent::actions();
unset($actions['update']);
unset($actions['delete']);
unset($actions['view']);
unset($actions['index']);
return $actions;
}
public function actionIndex($count = 10)
{
/** @var TweetLastfinder $tweetLastFinder */
$tweetLastFinder = Yii::$app->get('tweetlastfinder');
return $tweetLastFinder->findLastTweets($count);
}
响应内容正确但有视图:
curl -i -H "Accept:application/json" "http://192.168.100.5/index.php/tweets"
HTTP/1.1 200 OK
Date: Wed, 30 Mar 2016 12:15:36 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Content-Length: 2282
Content-Type: application/json; charset=UTF-8
[{"id":605,"text":"Popular Mus......
在这种情况下,我不能使用$serializer,显示_meta 等
我想使用来自组件的响应并逐页列出资源,因为它执行默认操作。应该怎么做才合适?
【问题讨论】:
标签: php rest controller yii2