Invalid argument supplied for foreach() Pagination - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Invalid argument supplied for foreach() Pagination (/showthread.php?tid=77235) |
Invalid argument supplied for foreach() Pagination - eleumas - 08-05-2020 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! RE: Invalid argument supplied for foreach() Pagination - InsiteFX - 08-05-2020 To show the pagination links you just do this: PHP Code: <?= $pager->links();?> You use the foreach to output your database records. RE: Invalid argument supplied for foreach() Pagination - eleumas - 08-05-2020 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/libraries/pagination.html#creating-the-view RE: Invalid argument supplied for foreach() Pagination - InsiteFX - 08-05-2020 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. RE: Pagination CodeIgniter 4 - eleumas - 08-07-2020 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! |