Pagination - Need Help

#1
[eluser]$ilovephp[/eluser]
Using the following codes in the controller:

Code:
function configure($base_url, $total_rows, $per_page)
{
$config = array
    (
    'base_url' => $base_url,
    'total_rows' => $total_rows,
    'per_page' => $per_page
    );
$this->pagination->initialize($config);
}
//where base_url = http://localhost/test_project/index.php/users/page

and this code in the view:

Code:
$this->pagination->create_links();

i was able to generate the pagination links, it does work, however, when i try to click links in the pagination it gives me desire results EXCEPT the FIRST page or the PAGE 1 of the pagination.

I mean, when i click 2 it gives me "http://localhost/test_project/index.php/users/page/2", also working in other pages except the first page which gives me "http://localhost/test_project/index.php/users/page/".

The first link will of course generate an error.

#2
[eluser]pickupman[/eluser]
You need to change your uri segment in your pagination config. You are using the 3rd segment for the offset set, so you would need:
Code:
function configure($base_url, $total_rows, $per_page, $segment ='2')
{
$config = array
    (
    'base_url' => $base_url,
    'total_rows' => $total_rows,
    'per_page' => $per_page,
    'uri_segment' => $segment
    );
$this->pagination->initialize($config);
}

And then pass 3 as the fourth parameter to your configure function.

#3
[eluser]$ilovephp[/eluser]
Thanks for the reply pickupman. I just figured out the problem. it is not about the segment since i have 3 as defult segment in my cofig file.

the page function that i created previously was accepting one argument, that is

Code:
function page($page)
{
...
}

and i used the $page as offset without minding that the third segment could be empty ... so i revised the function with:
Code:
function page()
{
if(!isset($this->uri->segment(3)))
$page = 1;
...
}

yet, thank you.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.