Invalid argument supplied for foreach() Pagination |
Hi, this is my Controller:
PHP Code: public function index() This is my view: PHP Code: <ul class="uk-pagination"> I have this error: Invalid argument supplied for foreach() Thanks for help me! ![]()
08-05-2020, 07:01 AM
(This post was last modified: 08-05-2020, 07:03 AM by InsiteFX. Edit Reason: spelling error )
To show the pagination links you just do this:
PHP Code: <?= $pager->links();?> You use the foreach to output your database records. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks for reply!
If i want use custom classes for <ul> and <li> and to have the button NEXT and PREV? I read this but doesn't work: https://codeigniter.com/user_guide/libra...g-the-view
08-05-2020, 08:13 AM
(This post was last modified: 08-09-2020, 04:16 AM by InsiteFX. Edit Reason: Fixed error in the bs_full.php file. )
You need to create your own I have 2 custom bootstrap 4 pagers here I will post them for you
1) you need to edit app/Config/Pager and add the two lines below to the $templates array. PHP Code: 'bs_full' => 'Pagers\bs_full', 2) Create a folder under your Views folder called Pagers and add these two views to ir app/Views/Pagers bs_full.php PHP Code: <?php app/Views/Pagers bs_simple.php PHP Code: <?php to load them in the controller and view is a little different Controller: PHP Code: ->paginate(3, 'group1'), And in the view you load it like this: PHP Code: <!-- Pagination --> See the group1 in the Controller code and the View code. The ( Justify-content-center ) In the <ul> is to center both Pagers you can remove it if you do not want them centered. That will show you how it is done. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
There is some error in your code in bs_full.php or something that doesn't work in my project because i have replace your code with the original code il CodeIgniter documentation and pagination work fine.
So, this is my code for pagination. I use UIkit framework and not Bootstrap. Change the HTML classes like you need. /app/Config/Pager.php PHP Code: <?php namespace Config; /app/Views/pagers/uk_full.php PHP Code: <?php $pager->setSurroundCount(2); ?> /app/Views/pagers/uk_simple.php PHP Code: <?php $pager->setSurroundCount(2); ?> In your view (for example under the items table): PHP Code: <?php /app/Controllers/NAME_OF_YOUR_CONTROLLER.php PHP Code: public function index() Enjoy! ![]() |
Welcome Guest, Not a member yet? Register Sign In |