在 Active Collab API 中获取分页结果 [英] Get pagination results in Active Collab API

查看:35
本文介绍了在 Active Collab API 中获取分页结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现您可以通过 api 像这样传入 page 参数来获得分页结果:

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 - 将等待回复.

I have created an issue on Github - will await a response.

现在,我执行以下操作:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆