在Active Collab API中获取分页结果 [英] Get pagination results in Active Collab API
本文介绍了在Active Collab API中获取分页结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚发现,您可以通过传入page参数来通过api获得分页结果:
I have just discovered you can get pagination results through the api by passing in the page parameter like so:
$projects = $client->get('projects/147/time-records?page=3')->getJson();
有没有一种方法可以知道一个项目有多少次记录,所以我知道我需要分页多少次?
Is there a way of knowing how many time records a project has so I know how many times I need to paginate?
或者,我将如何检索几页有价值的数据-我在代码中苦苦挣扎!
Alternatively, how would I go about retrieving several pages worth of data - i'm struggling with the code!
推荐答案
我在 Github -将等待响应.
现在,我执行以下操作:
For now, I do the following:
// Get all the projects
// Set the page number
$page = 1;
// Create an empty array
$project_records = array();
// Get the first page of results
$project_records_results = $client->get('projects?page=' . $page)->getJson();
// Merge the results with base array
$project_records = array_merge($project_records, $project_records_results);
// Get the next page of results,
// if it returns something merge with the base array and continue
while ($project_records_results = $client->get('projects?page=' . ++$page)->getJson()) {
$project_records = array_merge($project_records, $project_records_results);
}
这篇关于在Active Collab API中获取分页结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文