How to paginate model using join? - 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: How to paginate model using join? (/showthread.php?tid=79099) |
How to paginate model using join? - sfarzoso - 04-19-2021 I have declared this model: PHP Code: <?php I usually apply the pagination in the following way: PHP Code: $post = new PostModel(); and then I send `$posts` and `$pager` to the view, this mechanism works just fine, but how can I paginate the post using a join? Essentially I need to return all the blog_posts records which contains meta in the `blog_post_meta` table, this is the structure of the two tables: blog_posts id | title | content blog_post_meta id | post_id | meta_key | meta_value how can I use the paginate replicating this query? PHP Code: return $this->builder() RE: How to paginate model using join? - iRedds - 04-19-2021 PHP Code: public function myPaginateMethod() RE: How to paginate model using join? - sfarzoso - 04-19-2021 (04-19-2021, 09:53 AM)iRedds Wrote: Thanks for the answer, but I don't get it, I return this from the model: PHP Code: public function getPostByMeta(string $key, string $value) then in the controller: PHP Code: $posts = $this->post->getPostByMeta('tag', $tag->id)->paginate(10); I get: undefined method paginate also, how can I access to pager? RE: How to paginate model using join? - iRedds - 04-19-2021 paginate is a model method. Therefore, your method must return an instance of the model. You are returning a Builder instance. See the examples I wrote more carefully. |