22Using Entity Classes
33#####################
44
5- CodeIgniter supports Entity classes as a first-class citizen in it's database layer , while keeping
5+ CodeIgniter supports Entity classes as a first-class citizen, while keeping
66them completely optional to use. They are commonly used as part of the Repository pattern, but can
77be used directly with the :doc: `Model </models/model >` if that fits your needs better.
88
@@ -16,9 +16,17 @@ Entity Usage
1616
1717At its core, an Entity class is simply a class that represents a single database row. It has class properties
1818to represent the database columns, and provides any additional methods to implement the business logic for
19- that row. The core feature, though, is that it doesn't know anything about how to persist itself. That's the
19+ that row.
20+
21+ .. note :: For ease of understanding, the explanation here is based on the case of
22+ using a database. However, Entity can also be used for data that does not come
23+ from a database.
24+
25+ The core feature, though, is that it doesn't know anything about how to persist itself. That's the
2026responsibility of the model or the repository class. That way, if anything changes on how you need to save the
21- object, you don't have to change how that object is used throughout the application. This makes it possible to
27+ object, you don't have to change how that object is used throughout the application.
28+
29+ This makes it possible to
2230use JSON or XML files to store the objects during a rapid prototyping stage, and then easily switch to a
2331database when you've proven the concept works.
2432
@@ -70,7 +78,7 @@ access them as if they were public properties. The base class, ``CodeIgniter\Ent
7078well as providing the ability to check the properties with ``isset() ``, or ``unset() `` the property, and keep track
7179of what columns have changed since the object was created or pulled from the database.
7280
73- .. note :: The Entity class stores the data in the property ``$attributes``.
81+ .. note :: The Entity class stores the data in the class property ``$attributes`` internally .
7482
7583When the User is passed to the model's ``save() `` method, it automatically takes care of reading the properties
7684and saving any changes to columns listed in the model's ``$allowedFields `` property. It also knows whether to create
0 commit comments