What is an Entity in CodeIgniter 4?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid CodeIgniter basics — a prerequisite for any developer role.

Answer

A Entity in CodeIgniter 4 is a class that represents a row of data, similar to an ORM model. Extend CodeIgniter\Entity\Entity. Entities provide automatic casting via the $casts property: protected $casts = ["is_active" => "boolean", "options" => "json", "created_at" => "datetime"] — values are automatically converted when set or retrieved. You can also define getter and setter methods using the getPropertyName() / setPropertyName() convention for mutators. Access properties: $user->name, $user->created_at->format("Y-m-d"). Link a model to an entity: protected $returnType = "App\Entities\User" in the model — all queries now return entity objects. Entities bring a cleaner domain model without the full weight of an ORM.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex CodeIgniter answers easy to follow.