CI 4 pagination problem - 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: CI 4 pagination problem (/showthread.php?tid=77579) |
CI 4 pagination problem - lukasz.bluedragon - 09-20-2020 How do I paginate only selected items from a table. Controller: PHP Code: <?php Model: PHP Code: <?php View PHP Code: <!doctype html> Zawsze dostaję błąd: Illegal string offset 'id' w widoku. RE: CI 4 pagination problem - InsiteFX - 09-20-2020 I also had problems at first and I ended up doing this. The code should give you an idea of how to do it, you will notice I am returning $this so that we can use method chaining. Don't worry about the group stuff it's because I have custom bootstrap pager templates. PHP Code: // CONTROLLER This works like a charm for me. RE: CI 4 pagination problem - lukasz.bluedragon - 09-22-2020 Thank you, it also worked for me. I'm just wondering how to do it by writing SQL queries? RE: CI 4 pagination problem - InsiteFX - 09-22-2020 Just run the queries and than return $this Which allows you to chain on the paginate method. So: PHP Code: $data['test'] = $model->yourQuery->paginate(10); Don't tell your model methods to return any object or array the paginate uses the find method to return everything. RE: CI 4 pagination problem - nc03061981 - 09-23-2020 With Query, you can 1. Get current page: $curPage = $pager->getCurrentPage(); 2. In your query, use LIMIT: LIMIT $curPage * $perPage, $perPage |