使用 zend_ldap 限制 LDAP 请求的结果
我实际上正在使用 Zend Framework,我想从 ldap 目录获取信息。为此,我使用以下代码:
$options = array('host' => '...', 'port' => '...', ...);
$ldap = new Zend_Ldap($options);
$query = '(username=' . $_GET['search'] . ')';
$attributes = array('id', 'username', ...);
$searchResults = $ldap->search($query, $ldap->getBaseDn(), Zend_Ldap::SEARCH_SCOPE_SUB, $attributes);
$ldap->disconnect();
可能有很多结果,所以我想通过限制结果数量来实现分页。我在 Zend_Ldap 的 search() 函数的参数中进行了搜索,它有一个排序参数,但没有给出间隔。
您是否有限制结果数量的解决方案(例如在 sql 中限制 0、200)?
谢谢
I'm actually working with Zend Framework and I would like to get informations from a ldap directory. For that, I use this code :
$options = array('host' => '...', 'port' => '...', ...);
$ldap = new Zend_Ldap($options);
$query = '(username=' . $_GET['search'] . ')';
$attributes = array('id', 'username', ...);
$searchResults = $ldap->search($query, $ldap->getBaseDn(), Zend_Ldap::SEARCH_SCOPE_SUB, $attributes);
$ldap->disconnect();
There is may be many results so I would like to realize a pagination by limiting the number of results. I searched in the paramters of the search() function of Zend_Ldap which have a sort parameter but nothing to give an interval.
Do you have a solution to limit the number of results (as in sql with limit 0, 200 for example) ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
客户端请求的大小限制可用于限制目录服务器将返回的条目数。但是,客户端请求的大小限制不能覆盖任何服务器施加的大小限制。这同样适用于时间限制。所有搜索都应包括非零的大小限制和时间限制。不包括大小限制和时间限制是非常糟糕的形式。请参阅“LDAP:编程实践”和 “LDAP:搜索实践”了解更多信息。
“分页”是使用简单的分页结果控件扩展来完成的。在我的博客文章中描述: "LDAP:简单分页结果”。
或者,如果您的 API 支持搜索结果侦听器,则可以使用搜索结果侦听器在结果到达时对其进行处理,这将减少应用程序的内存需求。
A client-requested size limit can be used to limit the number of entries the directory server will return. The client-requested size limit cannot override any server-imposed size limit, however. The same applies to the time limit. All searches should include a non-zero size limit and time limit. Failure to include size limit and time limit is very bad form. See "LDAP: Programming Practices" and "LDAP: Search Practices" for more information.
"Paging" is accomplished using the simple paged results control extension. described in my blog entry: "LDAP: Simple Paged Results".
Alternatively, a search result listener, should your API support it, could be used to handle results as they arrive which would reduce memory requirements of your application.
不幸的是,当前版本的 PHP 不支持开箱即用的 ldap 分页功能 - 请参阅 http://sgehrig.wordpress.com/2009/11/06/reading-paged-ldap-results-with-php-is-a-show-stopper/
如果您有控制权在您的服务器环境中,您可以使用 PHP 5.3.2(也可能是其他版本)安装一个补丁,该补丁将允许您执行此操作:https://bugs.php.net/bug.php?id=42060。
....或者您可以等到 5.4.0 发布用于生产,这应该在接下来的几周内发布,并且包含此功能。
如果您要使用补丁,则需要使用 ldap_control_paged_results() 和 ldap_control_paged_results_response() 函数。我认为它们在 5.4 中已被重命名为单数 ldap_control_paged_result() 和 ldap_control_paged_result_response()。
祝你好运!
Unfortunately, current releases of PHP don't support the ldap pagination functions out of the box - see http://sgehrig.wordpress.com/2009/11/06/reading-paged-ldap-results-with-php-is-a-show-stopper/
If you have control of your server environment, there's a patch you can install with PHP 5.3.2 (and possibly others) that will allow you to do this: https://bugs.php.net/bug.php?id=42060.
.... or you can wait until 5.4.0 is released for production, which should be in the next few weeks, and which include this feature.
ldap_control_paged_results() and ldap_control_paged_results_response() are the functions you'll want to use if you're going with the patch. I think they have been renamed to the singular ldap_control_paged_result() and ldap_control_paged_result_response() in 5.4.
Good luck!