2
2
Using Entity Classes
3
3
#####################
4
4
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
6
6
them completely optional to use. They are commonly used as part of the Repository pattern, but can
7
7
be used directly with the :doc: `Model </models/model >` if that fits your needs better.
8
8
@@ -16,9 +16,17 @@ Entity Usage
16
16
17
17
At its core, an Entity class is simply a class that represents a single database row. It has class properties
18
18
to 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
20
26
responsibility 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
22
30
use JSON or XML files to store the objects during a rapid prototyping stage, and then easily switch to a
23
31
database when you've proven the concept works.
24
32
@@ -70,7 +78,7 @@ access them as if they were public properties. The base class, ``CodeIgniter\Ent
70
78
well as providing the ability to check the properties with ``isset() ``, or ``unset() `` the property, and keep track
71
79
of what columns have changed since the object was created or pulled from the database.
72
80
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 .
74
82
75
83
When the User is passed to the model's ``save() `` method, it automatically takes care of reading the properties
76
84
and saving any changes to columns listed in the model's ``$allowedFields `` property. It also knows whether to create
0 commit comments