2
votes

I know their are a few questions on codeigniter pagination but from what I can tell they dont seem to be relevent.

FYI I am using page numbers in my URL, not the index (using config option use_page_numbers)

So my problem is the first link.

My url structure for a page other than page 1 is:

http://www.something.com/foo/page/x

That all works fine however when I hover over the link for page 1 the url that comes up is:

http://www.something.com/foo/page/

Now i know thats because ive declared the base url as:

$config['base_url'] = $this->uri->slash_segment(1, 'both') . 'page/';

But is it possbile to either have the URl for page 1 as:

http://www.something.com/foo/

OR

http://www.something.com/foo/page/1/

Hope that makes sense and someone can help out. I did try setting the base_url to page/1 if the 3rd segment was empty but no joy.

thanks for reading

4
Why do you need to use "page/1" in your link ? You can use "page" as "page/1" at least for functionality - mirza

4 Answers

8
votes

Imagine your base_url is :

$config['base_url'] = base_url() . 'method/page/';

So, change the code like below to have the first URL as you wish :

$config['base_url'] = base_url() . 'method/page/';
$config['first_url'] = '1';
$this->pagination->initialize($config);

Now the first page link should be:

http://example.com/method/page/1

1
votes

This thing happens because you are adding 'page/' parameter to pagination base url

Just change your configuration for pagination. Set it as below:

$pagination['base'] = $this->config->item('base_url');
$config['base_url'] = $pagination['base'].'foo';

This works and the pagination link for the first page will be http://www.something.com/foo/

1
votes

I just ended up having the URL with the /foo/ without the 'page' segment in there. This was done using the normal method from the docs:

http://codeigniter.com/user_guide/libraries/pagination.html

Thanks to everyone for your input though.

0
votes

Use Following code: $FullURL = explode('?',$_SERVER['REQUEST_URI']);
$config['first_url'] = base_url() . 'test/testing?'.$FullURL[1];

$this->pagination->initialize($config);

This is will solve your issue.