简体   繁体   English

CodeIgniter分页 - 第一页的链接不起作用,为什么?

[英]CodeIgniter Pagination - first page’s link doesn’t work, why?

I use pagination library on my site, my config is here: 我在我的网站上使用分页库,我的配置在这里:

$data['url_keyword'] = url_title($keyword, '_');
$config['base_url'] = base_url().'image/'.$data['url_keyword'].'/';
$config['per_page'] = 1;
$config['uri_segment']=3; 

my urls are: mysite/image/keyword/1 (page2), mysite/image/keyword/2 (page3), mysite/image/keyword/3 (page4), mysite/image/keyword/4 (page5) 我的网址是: mysite/image/keyword/1 (page2), mysite/image/keyword/2 (page3), mysite/image/keyword/3 (page4), mysite/image/keyword/4 (page5)

When I'm on page 2 ( mysite/image/keyword/1 ) and click previous - it gets me into mysite/image/keyword/ - which doesnt work, but mysite/image/keyword/0 WORKS. 当我在第2页( mysite/image/keyword/1 )并点击上mysite/image/keyword/ - 它会让我进入mysite/image/keyword/ - 这不起作用,但是mysite/image/keyword/0 Library just doesn't add zero at the end of url. 库只是在url的末尾不添加零。

how to fix it? 怎么解决?

Try this: 尝试这个:

if (!$this->uri->segment(3))
       $page = 0;

//Your other logic

By default if $this->uri->segment(x) is empty it will return false. 默认情况下,如果$this->uri->segment(x)为空,则返回false。 Without seeing your controller or view I can't be more specific on where to place this or what you are naming your variable. 在没有看到您的控制器或视图的情况下,我无法更具体地说明放置它的位置或命名变量的内容。 This should work in the instances in which you call: yoursite.com/image/keyword 这应该适用于您调用的实例:yoursite.com/image/keyword

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM