Closed Furgas closed 9 years ago
That's simple! You can request the data to be returned to you in pages by first enabling paged responses before you send your search query.
Once you have a response, you can extract the cookie from it via this method. You will need to use the cookie on subsequent requests as the last parameter of the pagedResult()
method.
So the whole process looks like this:
resultResponse()
with no cookie set (you do not have one yet)pagedResultResponse()
Thanks. Before I asked the questions, I tried to search for ldap_control_paged_result_response with github search but found nothing.
The paged search process calls for some helper method.
It's here. :)
Github fails to find this function call because of the @ before it. Searching for _\@ldap_control_paged_resultresponse does the trick.
After some messing around I ended up with this code which seems to work.
$results = [];
$cookie = '';
do {
$ldap->pagedResult(1000, false, $cookie);
$response = $ldap->search($this->ldapSearchBase, $filter, $attributes);
$arr = $response->getEntries();
unset($arr['count']);
$results = array_merge($results, $arr);
$pagedArray = $response->pagedResultResponse();
$cookie = !empty($pagedArray['cookie'])?$pagedArray['cookie']:false;
} while ($cookie);
Optionally you can do
$cookie = $response->pagedResultResponse("cookie");
Which will give you just the cookie.
How should I, using this library, approach searching with pagination as shown in "Example _#_2 LDAP pagination" on http://php.net/manual/en/function.ldap-control-paged-result.php ?