Welcome Guest, Not a member yet? Register   Sign In
Pagination - links go up by 10 instead of 1?
#11

[eluser]TheFuzzy0ne[/eluser]
I see what you're saying, but to my understanding libraries are made to be as self contained as possible, and it's to save code. Using the pagination class as-is, there are no assumptions made about what code you have in place elsewhere (such as in your model). By working with the result offset rather than the page number, it's ready to use as it is, there's no logic that actually has to be added to your models to work out the actual offset, as some people might not understand how the calculations work.

However, with that said, I see no reason why it can't still use the actual page number from the URL, but return an offset to the model. Perhaps it would have been better this way, but then again, perhaps it confuses the issue. The pagination class would still need to know how many results there are, and how many results per page should be displayed. I think that in short, it saves developers having to do the calculations themselves.

Just out of interest, how would you have done this, assuming the user isn't wanting to add any logic to their model to calculate the offset from a page number? If we can agree on a better way, perhaps this could be implemented in the future. This is by no means the first instance I've seen where someone has asked this question.
#12

[eluser]Zeeshan Rasool[/eluser]
You have to give such limit for per page so this page limit can be used any where in the site.
I think its not CI library fault it may be design issue...
#13

[eluser]xwero[/eluser]
I've seen people get confused by the fact you add the per_page setting to the pagination config.
Code:
$data['content'] = $this->some_model->get_content();

$config['total_rows'] = count($data['content']);
$config['per_page'] = 10;
// ...
$data['pagination'] = $this->pagination->create_links();
And people assume by some magic functionality the model method is going to figure out which limit and offset needs to be added to the sql statement.

It's not confusing to have some calculations in your code because you are in control. If you obscure all calculations you are going to have to remember a whole lot more methods. And if you look at the methods code, it's going to be laughable and not in a good way.
Code:
function pagecount($total_records,$per_page)
{
   return ceil($total_records/$per_page);
}


I think the reason that so many people struggle with the class is because the documentation hasn't got a full example. It shows some configuration settings, loads them and echos the build method, create_links.

for your question, look at the hack in my previous answer. it doesn't matter if you use the uri->segment method or use an optional parameter of the controller method to identify the pagination segment, the calculation will be correct. With no added logic in the model.
#14

[eluser]Zeeshan Rasool[/eluser]
Can some one test this Hope its for all...

------> CI Pagination
#15

[eluser]cdsuze[/eluser]
Hello guys, my first post after 4 weeks as a real lurker..

I had the same problem and did my own hack for this..Of course there are several ways and as TheFuzzy0ne is saying, yo DO have the ability to do whatever you want..

But I don't think this is the point...for instance, 'per_page' parameter according to the user guide is
"The number of items you intend to show per page".

Setting this to 1 is not something easy to figure out (for slower-than-average-brains like mine Smile).

If the offset is useful for developers then it can be an internal variable/method of the Pagination class...but not something used for the create_links method....I did my own (basic) create_links_pages with page numbers instead of offset...maybe having two methods in the core library in future versions can help that fewer people needs to hack it..

Also, I just want to thank this community for the help as a lurker Smile

Best regards,

César Enrique
#16

[eluser]TheFuzzy0ne[/eluser]
I'm glad you find the forums helpful. Thanks for your comments.




Theme © iAndrew 2016 - Forum software by © MyBB