Models as Entities using PHP Traits |
There are a couple of debates in some companies I've worked for about models being entities or not. In CI3, it usually ended something with 2 files: models/User_model.php and models/entities/User.php.
CI3 Example: PHP Code: $i = $this->input; But for future enhancements of CI4, PHP Traits can be used instead of extending \CodeIgniter\Model. CI4 Example: PHP Code: final class UserModel This can be useful for something like: PHP Code: final class App The reason for this is for the developer to have the flexibility of whether or not his model is a real model, which can connect to a database, or just a plain entity by not using any model Traits at all.
Long live CodeIgniter!
A feature that I didn't know about until about 1 year ago in CI was the ability to have the database results returned as any class that you can set the attributes on. I've become a big fan of the Repository pattern, myself, and that helped make it all work together pretty seamlessly.
That way you have the user_model which handles mainly working with the database to find, save, etc the data. Then entity classes, just like you've mentioned have zero parent classes and are completely standalone. Oh - and this absolutely made it's way over to CI4. |
Welcome Guest, Not a member yet? Register Sign In |