How to create pagination on CI4 |
Hi, I'm having a lot of trouble figuring out how to create pagination on Codeigniter 4.
This is my controller: PHP Code: $model = new TestModel(); This is the model: PHP Code: public function getItem($slug = false){ While in the view I recall the pagination. As you can see in the model I create the query to retrieve the results, while in the controller I call the model and pager. But I don't know what else to do, I don't understand how and why to use paginate ()
Can someone help me? I just can't understand the functionality of paginate ()
$pager = \Config\Services::pager();
if($this->request->uri->getTotalSegments() == 4) { $page = $this->request->uri->getSegment(4); } else { $page = 1; } $perPage = 2; $data['pages'] = $pager->makeLinks(1, $perPage, 20,'front_full'); echo $pages in your view like <?=$pages?>
Here you find the basics:
https://codeigniter.com/user_guide/libra...ation.html? The Model is not displayed but it could look like this: PHP Code: <?php namespace App\Models; I am trying not CRUD but the pagination links "$pager->links()" is not working and even changing it manually, in the browser navigation bar, the same page is always displayed.
I was unable to find a solution. Since paginate () automatically fetches the results from the main table, I cannot act on a query in order to add orderBy.
My site is local, catalogs of films and records, it was developed with CI3, no problem so far, currently I only update the tables.
Out of curiosity I tried to use CI4 using the same database but I am about to give up, like you I am stuck in the pagination. I think that something is only automated when you have mastered the manual, but I don't, or at least there is something saying how to do it. I am aware of my limitations, which is certainly the reason why I am unable to go further. It's a hobby for me, CI3 meets my needs, who knows later. I am on the edge of the abyss ... about to fly. I'm sorry, I did my best.
(04-09-2020, 01:01 PM)wdeda Wrote: My site is local, catalogs of films and records, it was developed with CI3, no problem so far, currently I only update the tables. Until a few weeks ago, I also did with CI3, but with the new release of version 4 it is always better to update. There is to learn and making many mistakes, thanks anyway. |
Welcome Guest, Not a member yet? Register Sign In |