Kohana 3.1 查询计数和查询分页
我正在接触 Kohana,但在分页方面遇到了麻烦。我收到以下错误:
ErrorException [致命错误]:类 未找到“分页”
在非官方维基之后
Kohana::modules(array( 'database' => MODPATH.'database', 'userguide' => MODPATH.'userguide', 'pagination' => MODPATH.'pagination', ))
我修改了引导文件以包含此内容:但这似乎没有帮助。
我的第二个问题是关于查询计数......我很惊讶没有像 $query-count() 这样的函数,除非我选择 ORM 相反,我发现这个解决方案有点笨拙,因为查询计数是每个分页请求:
$result['count'] = $pagination_query->select('COUNT("*") AS result_count')->execute()->get('result_count');
有什么建议吗?
非常感谢
I am getting my feet wet with Kohana but having trouble with pagination. i get the following error :
ErrorException [ Fatal Error ]: Class
'Pagination' not found
following the unoffical wiki I amended the bootstrap file to include this:
Kohana::modules(array( 'database' => MODPATH.'database', 'userguide' => MODPATH.'userguide', 'pagination' => MODPATH.'pagination', ))
but that didn't seem to help.
my second question is with regards to query count.... I am surprised there is no function like $query-count() unless i opt for ORM instead i find this solution a bit clunky given that a query count is a must for every pagination request:
$result['count'] = $pagination_query->select('COUNT("*") AS result_count')->execute()->get('result_count');
Any suggestions?
thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Kohana 3.1 没有附带分页模块...
下载
必须从https://github.com/kohana/pagination
,然后转到 class/kohana编辑第 199 行,从 ->uri 到 ->uri(),
进行操作
它对查询计数
......仍在搜索。希望这对某人有帮助
Kohana 3.1 does not come with the pagination module...
it must be downloaded from
https://github.com/kohana/pagination
then go to the class/kohana edit line 199 from ->uri to ->uri()
that does it
as to the query count....still searching.
hope this helps someone
Database 类中曾经有一个 count_last_query() 函数,它提供最后一次查询运行的总结果,因为它没有任何限制或偏移,但他们从版本 3.0.9 中提取了它。您可以在这里找到它的文档:
http://kohanaframework.org/3.0/guide/ api/Database#count_last_query
我实际上已经在该函数的代码的基础上构建了我自己的计数查询函数(如果您想使用它)。
There used to be a count_last_query() function in the Database class which provided the total results of the last query run as it would be without any limit or offset, but they pulled it from version 3.0.9. You can find the documentation of it here:
http://kohanaframework.org/3.0/guide/api/Database#count_last_query
I've actually built upon the code from that function to make my own count query function if you want to use that.