0

Why does CI Wiz use entities instead of plain arrays?

The generated models return typed entity objects. What is the benefit of this over returning associative arrays, especially for developers coming from CI 3?
Posee par Inconnu Jan 29, 2026 85 vues

1 reponse

0
✓ Acceptee
CI4 entities give you typed, predictable objects instead of anonymous associative arrays. The benefits are practical: - **Type safety**: fields are cast to their declared types (int, bool, datetime) automatically, so you stop getting ``"1"`` instead of `true` from TINYINT(1) columns. - **Autocomplete**: your IDE knows the entity's properties and can complete them, which associative arrays cannot offer. - **Encapsulation**: you can add computed properties, mutators, and business logic to an entity class without touching the model. - **Portability**: an entity is a plain PHP class with no CI4 framework dependency in its interface, making it easy to use in contexts outside the framework. For developers coming from CI3 who are used to `$row->field` on a `stdClass` result, the mental model is essentially the same — the difference is that the class is explicit, documented, and typed.
Repondu par cantonner Jan 29, 2026

Veuillez vous connecter pour publier une reponse. vous connecter