Pagination with Custom model - 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: Pagination with Custom model (/showthread.php?tid=78305) Pages:
1
2
|
Pagination with Custom model - AndreaL - 12-31-2020 Hi all, I currently use pagination with Codeigniter Model but I cannot find how to use it with CUSTOM models. Here is my code: CONTROLLER PHP Code: <?php namespace App\Controllers; And here is the MODEL PHP Code: public function annunci(){ I know I need to load the pager somewhere and somehow but cannot figure out how to do it. Can anyone please show me on the above code? Thanks a lot RE: Pagination with Custom model - InsiteFX - 12-31-2020 Pagination RE: Pagination with Custom model - AndreaL - 01-04-2021 (12-31-2020, 12:27 PM)InsiteFX Wrote: Pagination I referred to documentation but there are no examples as to how to use it with custom models. I tried several times to add pieces of code on the one I showed but with no success. That's why I'am asking if anyone can show how to properly load the library and use pagination in the query since I was not able to. RE: Pagination with Custom model - seunex - 01-04-2021 Pagination in the docs only talk about the model method only does not give hint for those using query builder. You see I also find it hard finding my way in this pagination too using query builder i could not get it so I end up using third party pagination library from github. That solve my problems. RE: Pagination with Custom model - includebeer - 01-04-2021 What do you mean by custom model? I have examples for pagination in these 2 articles: https://includebeer.com/en/blog/how-to-build-a-basic-web-application-with-codeigniter-4-part-4 https://includebeer.com/en/blog/how-to-build-a-basic-web-application-with-codeigniter-4-part-5 RE: Pagination with Custom model - rmcdahal - 01-04-2021 This is how I am doing and working perfectly Code: public function index($keyword = null) RE: Pagination with Custom model - Mostafa Khudair - 01-04-2021 (12-31-2020, 03:59 AM)Here we go. Wrote: CONTROLLER: It's very recommended to read userguide RE: Pagination with Custom model - AndreaL - 01-07-2021 (01-04-2021, 05:33 AM)includebeer Wrote: What do you mean by custom model? Hi, if you refer to my question I have posted the code. By "custom model" I mean that I am not extending codeigniter's model but I have built a model of my own. If I extend Codeigniter's model I have no problem with pagination. But with the custom model it does not work. On the code I have posted, how would you add pagination? (01-04-2021, 10:04 AM)Mostafa Khudair Wrote:(12-31-2020, 03:59 AM)Here we go. Wrote: CONTROLLER: Hi, I believe your answer assumes I am extending Codeigniter's model, am I right? If so, I am not doing that. Mine is a custom model RE: Pagination with Custom model - berendbotje91 - 01-07-2021 (01-07-2021, 02:31 AM)AndreaL Wrote: Hi, if you refer to my question I have posted the code.Your code doesn't really explain how it is considered a "custom" model. Its only a function. It also doesn't explain why you don't want to extend codeigniters model. You aren't doing anything different that would not be possible in an extended model. So to most reading this topic, the way to make pagination work for you is to extend CodeIgniters Model. Because pagination is part of CodeIgniters Model, making a "custom model" also requires you to write your own code for pagination. RE: Pagination with Custom model - includebeer - 01-07-2021 Ok, it wasn’t clear your model do not extend CodeIgniter’s model. We just see one function. If you really don’t want to extend the Model class you can take a look at how the pagination is implemented in this class: https://github.com/codeigniter4/CodeIgniter4/blob/v4.0.4/system/Model.php#L1165 You will need to use the Pager service. You can’t call findAll() because it’s part of the Model class, so you will need to call the limit() function of the query builder to set the limit and offset for the select query. PHP Code: /** |