pawel
pawel

Reputation: 6146

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)

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. Library just doesn’t add zero at the end of url.

how to fix it?

Upvotes: 1

Views: 829

Answers (1)

brightintro
brightintro

Reputation: 1016

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. 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

Upvotes: 3

Related Questions