Custom ORM - Suggestions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Custom ORM - Suggestions (/showthread.php?tid=73015) |
Custom ORM - Suggestions - milosh-96 - 03-10-2019 Hello, I switched from Laravel to CodeIgniter, I really like simplicity" and freedom that CI brings. Since I only miss Eloquent in CodeIgniter I started working on my own. My plan isn't something advanced, I want to have relationships and some methods like isSomething(). How it works: In models I have methods like all(), find($id)... In those methods are $this->db queries. Also, I have Entities. You can see that I run foreach in all() method and there I create Entity instances. I really like this because I can have relationships or some methods that I can access everytime without writing new queries. For example, I have method isPublic() that checks if column "access_level" isn't set to "private". There should be something like BaseEntity class or interface that each Entity will extend/use but this is just a prototype. The one thing that really annoys me is this "require_once" call at the top. Is there a better way to load those classes? I would like to know what do you think about this and what should be improved Thanks. I appreciate any suggestions. (sorry if I posted in a wrong subforum) Controller: PHP Code: <?php Model: PHP Code: <?php Entity: PHP Code: <?php RE: Custom ORM - Suggestions - ciadmin - 03-10-2019 This sounds a bit like https://codeigniter4.github.io/CodeIgniter4/models/index.html#modeling-data, no? RE: Custom ORM - Suggestions - milosh-96 - 03-10-2019 I haven't checked that link so far. It's definitely what I want to have on my CI 3 project. RE: Custom ORM - Suggestions - ciadmin - 03-10-2019 That link is for CI4, definitely not compatible with CI3 ... could be a reason to look at migrating to the new version RE: Custom ORM - Suggestions - milosh-96 - 03-10-2019 I didn't express myself correctly in the last post, CI4 Entities are the best example of what I want to build for my CI3 project. I will consider CI4 for new projects but for now I will continue to work on this. |