我刚刚发现你可以通过 api 传递 page 参数来获取分页结果,如下所示:
$projects = $client->get('projects/147/time-records?page=3')->getJson();
有没有办法知道一个项目有多少时间记录,这样我就知道我需要分页多少次?
或者,我将如何检索几页有值(value)的数据 - 我正在为代码而苦苦挣扎!
最佳答案
我在 Github 上创建了一个问题- 将等待回复。
现在,我执行以下操作:
// 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);
}
关于php - 在 Active Collab API 中获取分页结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40020003/