如何使用 codeigniter 分页库回显页码?
我正在使用 codeigniter 分页库来对我的搜索结果进行分页。我使用限制和偏移来生成结果。
我想知道除了分页链接之外,如何回显用户当前正在查看的页面编号。
例如;
您当前正在查看 Y 个结果中的第 X 页。
这怎么可能?
I am using the codeigniter pagination library to page my search results. I am using a limit and an offset to generate the results.
I would like to know how, apart from in the pagination links, echo the number of the page the user is currently viewing.
For example;
You are currently viewing page X out of Y results.
How is this possible??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这也给出了当前页号,
其中 n 是段
This also gives the current page no
where n is the segment
您可以扩展 Pagination 类 (system/libraries/Pagination.php)。
创建一个名为 MY_Pagination.php 的文件,并将其放入 application/libraries/ 中,
将此代码添加到您的扩展分页类中;
不要忘记确保在 config.php 中将类扩展前缀正确设置为 MY_ (大约第 109 行),
然后您可以在控制器中访问它,如下所示:
您可以将其传递到您的视图中。
You could extend the Pagination class (system/libraries/Pagination.php).
Create a file called MY_Pagination.php and put it in application/libraries/
Add this code to your extend pagination class;
Don't forget to make sure the class extension prefix is set correctly to MY_ in the config.php (about line 109)
Then you can access it in your controller like;
Which you can pass into your view.
取决于您如何设置偏移量。我们的设置是通过每页的偏移量来设置的。所以我们的默认值是每页 10 个。因此,对于第一页,偏移量为 0。对于第二页,偏移量为 10,依此类推。因此,要获取当前页面,我会将偏移量除以当前限制加 1。因此
($cur_page/$per_page)+1
会获取当前页面。Depending on how you are setting up the offset. Ours is setup with an offset of the perpage. So our default is 10 per page. So for page one the offset is 0. For page two the offset is 10 and so on. So for me to get the current page I would take the offset divided by the current limit plus 1. So
($cur_page/$per_page)+1
would get me the current page.