Pagination and segment URIs |
I began writing a webapp in Codigniter 4 and currently, i'm stuck with the pagination.
I created a controller, a model an a view to retrieve database entries für usergroups and used CI's built-in pagination-library. UsergroupsModel: Code: <?php namespace App\Models; Controller (Usergroups): Code: <?php namespace App\Controllers; In the view, i got my pagination by using Code: <?= $pager->links() ?> The default pagination works fine, but i get an URI like https://DOMAIN.DE/usergroups?page=2 In the official Codeigniter 4 docs for the pagination, you can find the following: Quote:Specifying the URI Segment for Page It is also possible to use a URI segment for the page number, instead of the page query parameter. >Simply specify the segment number to use as the fourth argument. URIs generated by the pager would then >look like https://domain.tld/model/[pageNumber] instead of https://domain.tld/model?page=[pageNumber].:So in my controller i changed Code: $data['usergroups'] = $model->paginate(5); to Code: $data['usergroups'] = $model->paginate(5,'test',0,2); and in the view i added 'test' as a parameter. Code: <?= $pager->links('test') ?> In the Routes i added Code: $routes->get('usergroups/(:num)', 'Usergroups::index/$1'); and in the Controller i changed the index-function to Code: public function index($segment = null) The URIs generated from the pagination now look like this: https://DOMAIN.DE/usergroups/2 but it does not change anything in the entries and the pagination itself alway sticks to page 1. I think, i can not use CI's built in library when switching to segment-URIs and thus i need to create a manual pagination. Can somebody help me to fix this problem?
By the looks of things, there are a bug in 4.0.3, as the development version have changed how that feature works. And as of now (for you) it's broken. You need to load it manually for now.
https://codeigniter.com/user_guide/libra...e-manually PHP Code: $data['usergroups'] = $model->paginate(5, 'test', (int) $segment);
Great, that did the trick!
In the controller, i changed the function to Code: public function index($page = 1) and the $data['usergroups'] to Code: $data['usergroups'] = $model->paginate(5, 'test', $page, 2); Works like a charm ![]()
Great that it worked out for you, don't have an release date for then this is fixed and you don't need to manually assign it anymore.
|
Welcome Guest, Not a member yet? Register Sign In |