Welcome Guest, Not a member yet? Register   Sign In
Pagination when $config['per_page'] = 1
#1

[eluser]Cesar Kohl[/eluser]
Hi,

I use CI for more than 1 year now and I got this problem with Pagination library.

I want to make a book webpage, so page 1, 2, 3..

Here's the simple config, recommended in the User Guide, for pagination:

Code:
$this->load->library('pagination');

$config['base_url'] = base_url().'page/';
$config['total_rows']     = 10; //total pages
$config['per_page']     = 1;
$this->pagination->initialize($config);

echo $this->pagination->create_links();

So, the result is this:

1 2 3 > Last ›

BUT, the link of these anchors are:
Link 1: 'page/1'
Link 2: 'page/1' Must be two! OH NO
Link 3: 'page/2' Must be three! OH NO
...

Please, how can I fix it?
#2

[eluser]Krystian[/eluser]
try to pass
Code:
$config['uri_segment'] = 3; // or different digit depends on your URL
#3

[eluser]osci[/eluser]
[quote author="john_doe" date="1309132411"]try to pass
Code:
$config['uri_segment'] = 3; // or different digit depends on your URL
[/quote]

by default it is 3.

Quote:BUT, the link of these anchors are:
Link 1: ‘page/1’
Link 2: ‘page/1’ Must be two! OH NO
Link 3: ‘page/2’ Must be three! OH NO

The number shown is not the page, it's the offset. Your first page link is not page/1 it's page or page/0.
#4

[eluser]Cesar Kohl[/eluser]
Okay, I needed to put my hands on dirt to make this work.

Here is my new Pagination Class:

This replacement was made to work when $config['per_page'] (here $this->per_page) equals 1. What generally happens is that the value is the offset, and in this case must be the first (and only) value, the actual page.

Just insert it at 'application/libraries/' and it's done.

Of course, when $config['per_page'] > 1 it continues to work properly.

The file is attached.
#5

[eluser]osci[/eluser]
$Cesar
1)
Are you troubled with what offset is? You shouldn't do this kind of fix, which is a try ti mix page number and offset.
If you want your pager to have page number and not offset you have to change it to always deliver page numbers instead of offset, which you would have to calculate in your controller maybe to be turned into an offset and so be used in a query.

2)
When you want to extend a core class/lib etc you use MY_ prefix or whatever you have set, and since you want a new kind of pager you would create a new function create_number_links() for example.

Your solution is totally wrong approach. And it's not correct either
Code:
if($this->per_page == 1)
{
    $this->cur_page = floor(($this->cur_page/$this->per_page));
}
else
{
    $this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
}
How do you handle the offset for the db call?
#6

[eluser]Cesar Kohl[/eluser]
@osci I tested here my modifications and it works.. Maybe I'm doing the wrong tests so I can't see the error you're trying to show me.

If my approach is wrong I suggest you to show me a better one, please.
#7

[eluser]osci[/eluser]
[quote author="Cesar Kohl" date="1309231606"]@osci I tested here my modifications and it works.. Maybe I'm doing the wrong tests so I can't see the error you're trying to show me.

If my approach is wrong I suggest you to show me a better one, please.[/quote]

I'm not pointing code error to you, I'm pointing logical error. Your code might work for you, but it is not logical. You are mixing as I stated in a function the logic for page number and offset. You are going to work with offset when you want 4 records per page? Won't you then want page numbers too instead?
Also are you handling the offset? because for 1 record per page you get for first offset limit(1,0), while I think you are getting results for limit (1,1) for first record, unless you are handling that in your controller (computed from page number - remember page number is not offset.)

That being said, I already have provided you with example of what you should do - no code, just logic.
#8

[eluser]InsiteFX[/eluser]
Also if you try to compare it to MySQL:
MySQL = Offset, Limit

CI is Backwards from MySQL!
CI = Limit, Offset

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB