Welcome Guest, Not a member yet? Register   Sign In
Never been able to make the pagination work!
#1

[eluser]hbr[/eluser]
Hi,
It's all in the subject. I've been trying since CI 1.6.

Here is my simple code:

My controller:
Code:
function my_submissions($page=1) {
$PAGE_SIZE = 10;
$this->load->model('Submission');
            
$this->Submission->rows = $PAGE_SIZE;
$this->Submission->offset = ( $page - 1 ) * $PAGE_SIZE ;
$submissions = $this->Submission->get_list();
$total = $this->Submission->get_count();

$this->load->library('pagination');
            
            
$config['base_url'] = config_item('index_page') . '/members/my_submissions';
$config['total_rows'] = $total;
$config['uri_segment'] = 3;
$config['per_page'] = $PAGE_SIZE;
            
$this->pagination->initialize($config);
            
$paging = $this->pagination->create_links();
[...]
}

Okay, now when loading page 1 (/members/my_submissions/1), the db record n#1 is loaded as expected, the pagination links apprear BUT page 2 is selected instead of page 1 as default page.
When hovering over page 1 link, the link points to /members/my_submissions/ without any page number.
Page 3 points to /members/my_submissions/2
Page 4 points to /members/my_submissions/3
and so on.

So any idea please?
#2

[eluser]simshaun[/eluser]
The number in the url is an offset number, not a page number.
This had me confused for a couple hours a couple months ago..
#3

[eluser]hbr[/eluser]
this is really confusing.

Quote:$config['uri_segment'] = 3;

The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.

this is a portion from the docs, they clearly talk about a page number.

anyway, thanks simshaun.

one more thing, now it seems to work fine except that the link#1 still has no offset number in the URL, it is passed as blank.

any idea why this happens ?
#4

[eluser]simshaun[/eluser]
I agree the docs are confusing. Perhaps you could submit a bug report on that specific section of the docs.

Now, leaving link #1 blank is intentional, I think, because its offset is 0. You can set your parameter of the method to default to 0 to overcome this:
Code:
function my_submissions($offset = 0)
#5

[eluser]hbr[/eluser]
thanks m8 Wink




Theme © iAndrew 2016 - Forum software by © MyBB