Php 编码点火器';s分页导航don';行不通

Php 编码点火器';s分页导航don';行不通,php,codeigniter,pagination,Php,Codeigniter,Pagination,最后几天我在玩CI的分页。我已经设置好了配置,它运行得非常好。在控制器的函数中,我创建了一些检查url的IF语句 IF url is localhost/CI/index.php/controller/function/news THEN return first page of results from database -> first page BUT IF url is localhost/CI/index.php/controller/function/news/10 THEN

最后几天我在玩CI的分页。我已经设置好了配置,它运行得非常好。在控制器的函数中,我创建了一些检查url的IF语句

IF url is localhost/CI/index.php/controller/function/news
THEN return first page of results from database -> first page
BUT IF url is localhost/CI/index.php/controller/function/news/10
THEN return second page of results from database -> second page
但这是一个问题,因为只有在控制器的函数->localhost/CI/index.php/controller/function/10之后有大量结果时,CI的分页才能与导航一起工作

是否有任何解决方法可以使用以下url进行导航:localhost/CI/index.php/controller/function/news/10?
(我有新闻、分类和其他功能,我想展示一些关于它的基本信息。)

首先,你不需要使用if语句来检查它是第一页还是第二页,等等。。。Codeigniter将显示相应的数据。但是你可以做的是检查页码是否在那里

分页的工作方式是使用偏移量,并限制数据库的功能

因此,第1页将是:限制5(每页最大),偏移量:0(从0开始) 第2页:限制5(每页最多),偏移量:6

通常,codeigniter会检查url段(默认情况下为3)是否有效,如果无效,则会转到第1页


可能是代码本身不正确,您可能想发布它。

谢谢,我刚刚忘记在配置中添加uri_段。所以这个问题的答案是,我必须添加$config['uri_segment']=4;