How to loop pagination links using for loop instead of using foreach loop |
Hello everyone, I'm trying to loop link in my pagination template view, I want to be able to check various condition with the counter,
for example: PHP Code: <?php for($i = 1; $i <= count($pager->links()); $i++): ?> PHP Code: <?php foreach ($pager->links() as $link) : ?> Thank you in advance!
I really don't know why you need this, but did you try it like below? If it's associative array, it should work.
PHP Code: <?php for($i = 0; $i < count($pager->links()); $i++): ?>
Thank you @webdeveloper very much! It's working as expected, But I have a question about setting up the counter to begin with 1 instead of 0,
PHP Code: <?php I would like to hear any advice or alternatives of doing the same with ci4 pager.
Why not just add the key to the foreach like this:
PHP Code: <?php foreach ($pager->links() as $i => $link) : ?>
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Thank you very much @webdeveloper and @includebeer !.
Since I get trouble about extending Pager class, I have decided to add some methods to straight to the system with namespace: CodeIgniter\Pager in codeigniter4/framework/system/Pager/Pager.php. So I can get the page number only without full url. If is any way to extend pager class I would appreciate. Pager.php PHP Code: public function getNextPageNumber(string $group = 'default') Here its's my custom pagination working. PHP Code: <?php I would like to hear from you about what I did, Also to improve the best pagination that looks like this : prev 1 2 3 4 5 . . . 10 20 Next to the final results.
getCurrentPageNumber()
This method returns the page number of the current page. getPageCount() This method returns total number of pages. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-09-2022, 12:11 AM)InsiteFX Wrote: getCurrentPageNumber() (06-09-2022, 12:11 AM)InsiteFX Wrote: getCurrentPageNumber()
Then you must have something wrong in your code because I use both of those for displaying
Page 1 of 25 etc; And they work just fine. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-09-2022, 04:09 AM)InsiteFX Wrote: Then you must have something wrong in your code because I use both of those for displaying |
Welcome Guest, Not a member yet? Register Sign In |