0

You mention generating both models and entities — aren't they the same thing?

In most MVC frameworks a model and an entity are the same class. Why does CI Wiz generate two separate files for this?
Asked by Unknown Feb 11, 2026 86 views

1 Answer

0
✓ Accepted
In most MVC frameworks a "model" handles both data access and data representation, so they collapse into one class. CodeIgniter 4 separates them deliberately. In CI4, the **Model** is responsible for database interaction: queries, validation rules, the allowed fields list, soft-delete handling, and timestamps. The **Entity** is a typed PHP class that represents a single row of data — it holds the field values, declares their types (so a TINYINT(1) becomes a real `bool`, not the string `"1"`), and is where you put computed properties or mutators. The Model's default return type is set to the Entity class, so every query result comes back as a typed object rather than an anonymous array or stdClass. CI Wiz generates both files wired together correctly, which is exactly how CI4 intends them to be used.
Answered by cantonner Feb 11, 2026

Please sign in to post an answer. sign in