Article or other text pagination helper |
[eluser]Jelmer[/eluser]
This is a very simple helper to paginate articles by a simple string put between the pages. It's meant to be called just before the text you want to output is put into the view and in this example your text is in the $content variable: Code: $this->load->helper('paginate_text'); Code: $this->load->helper('paginate_text'); And here's the full helper paginate_text_helper.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Question to others: is there a more efficient way to get the same functionality without using ereg & ereg_replace so much? UPDATE: Now with previous and next links. UPDATE 2: changed explanation mistake and added suggestion if you'd like to paginate more than 1 item per page.
[eluser]theprodigy[/eluser]
I've actually written my own paginate class. It functions very similarly to CI's paginate class with one main difference. I didn't like the fact with CI's pagination class that if you had 10 pages and set the number of links to 2 (2 before and 2 after), but were on page 1, it only showed 3 links, and if you were on page 2, it would show 4 links, and from then on out to page 8, it would show the 5 links you requested. Then it would go back to 4 links on page 9, and 3 links on page 10. My class asks for the number of pages you want shown, not the number of links before/after. My class also allows you to set things via a generic config function, or individual setter methods. What is returned is an array: Code: array( The code, I believe, is very well documented. I tried having a couple people alpha test it, but I have yet to hear any response. You can download it here: Paginate Class Please let me know what you think of this class, whether good or bad. I would love to hear your input. P.S. This is basic pagination, not article pagination like Jelmer's listed above.
[eluser]theprodigy[/eluser]
I forgot to mention, it's made to be a library, not a helper. And it doesn't use any CI specific functionality, so it can be used outside CI applications (if you do that kinda stuff ;-) )
[eluser]Jelmer[/eluser]
Wow, I forgot about this helper (even though it's integrated into a CMS of mine). There's a lot of inefficiency in it: the use of ereg instead of preg for regular expressions and ereg where also strpos(), str_replace() or even substr() could be used. Also the use of count() within the definition of a for-loop (which caused the function call on each iteration). I'll rewrite this shortly to make it a lot more efficient. Also: arguements 2,3 and 4 aren't necessary - they can all be gotten from the CI superobject with get_instance(). @theprodigy: this doesn't have anything to do with my helper, it should have it's own topic.
|
Welcome Guest, Not a member yet? Register Sign In |