Using the built-in pagination functions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Using the built-in pagination functions (/showthread.php?tid=81064) |
Using the built-in pagination functions - sjender - 01-20-2022 Hi, I would like to implement the pagination library for retrieving logs from the database. This is one of my methods in a model: PHP Code: public function getAllLogs(?string $searchString = null, int $limit = 50): array Please note that I have edited it a bit to be readable and safe here.... The manual tells me to do this: PHP Code: $model = new \App\Models\UserModel(); And how can I pass my variable $searchString ? RE: Using the built-in pagination functions - iRedds - 01-20-2022 The Model::paginate() method uses the Model and QueryBuilder methods to retrieve data. PHP Code: $model = new \App\Models\UserModel(); PHP Code: $model->where('a', 'b')->paginate(10); You can move the conditions to a separate method. PHP Code: //model Using $this->db->query() immediately executes the query and cannot be used with the Model::paginate() method. RE: Using the built-in pagination functions - xenomorph1030 - 01-20-2022 To add to the response, if you want to use your method, you'll have to rely on manual pagination on the view. https://codeigniter.com/user_guide/libraries/pagination.html#manual-pagination Your current query also does not support pagination as it lacks a variable offset (currently set to 0). RE: Using the built-in pagination functions - sjender - 01-21-2022 OK, I will use the query builder intead. But that raises a new question.... In my controller I now have this: PHP Code: //used session to remember the searched value when browsing to another page in paginator My Logging Model now only has a createLogging() and deleteLogging() method. These are easily converted to the query builder and put into the controller, but should I? And what are the pro's of using the query builder over $this->db.->query? RE: Using the built-in pagination functions - kenjis - 01-21-2022 See Important in https://codeigniter4.github.io/CodeIgniter4/libraries/pagination.html#paginating-database-results RE: Using the built-in pagination functions - sjender - 01-21-2022 Yes, I have read that. But that's not really my question The paginator now works. But that raised a new question. Since the paginator is also kind of a query.... Which queries should I place in the controller, and which ones in the Model? RE: Using the built-in pagination functions - InsiteFX - 01-21-2022 All queries should be placed in your model. My Pagination uses my Bootstrap 5 Pagination Template. Model: PHP Code: /** Controller: PHP Code: /** RE: Using the built-in pagination functions - sjender - 02-02-2022 Just a following question.... In my view I want to show how many results are displayed. For example: Users: 20 of 35 I know there is a $pager->getTotal(). But is there also a method for returning the number of results on that page? |