@@ -106,13 +106,13 @@ Now that all of the pieces are in place, you would work with the Entity class as
106106 $user->email = 'foo@example.com';
107107 $userModel->save($user);
108108
109- You may have noticed that the User class has not set any properties for the columns, but you can still
110- access them as if they were public properties. The base class, ** CodeIgniter\\ Entity ** , takes care of this for you, as
111- well as providing the ability to check the properties with ** isset() ** , or ** unset() ** the property, and keep track
109+ You may have noticed that the `` User `` class has not set any properties for the columns, but you can still
110+ access them as if they were public properties. The base class, `` CodeIgniter\Entity \Entity `` , takes care of this for you, as
111+ well as providing the ability to check the properties with `` isset() `` , or `` unset() `` the property, and keep track
112112of what columns have changed since the object was created or pulled from the database.
113113
114- When the User is passed to the model's ** save() ** method, it automatically takes care of reading the properties
115- and saving any changes to columns listed in the model's ** $allowedFields ** property. It also knows whether to create
114+ When the User is passed to the model's `` save() `` method, it automatically takes care of reading the properties
115+ and saving any changes to columns listed in the model's `` $allowedFields `` property. It also knows whether to create
116116a new row, or update an existing one.
117117
118118.. note :: When we are making a call to the ``insert()`` all the values from Entity are passed to the method, but when we
@@ -123,7 +123,7 @@ Filling Properties Quickly
123123
124124The Entity class also provides a method, ``fill() `` that allows you to shove an array of key/value pairs into the class
125125and populate the class properties. Any property in the array will be set on the Entity. However, when saving through
126- the model, only the fields in $allowedFields will actually be saved to the database, so you can store additional data
126+ the model, only the fields in `` $allowedFields `` will actually be saved to the database, so you can store additional data
127127on your entities without worrying much about stray fields getting saved incorrectly.
128128
129129::
@@ -198,7 +198,7 @@ Here's an updated User entity to provide some examples of how this could be used
198198
199199The first thing to notice is the name of the methods we've added. For each one, the class expects the snake_case
200200column name to be converted into PascalCase, and prefixed with either ``set `` or ``get ``. These methods will then
201- be automatically called whenever you set or retrieve the class property using the direct syntax (i.e., $user->email).
201+ be automatically called whenever you set or retrieve the class property using the direct syntax (i.e., `` $user->email `` ).
202202The methods do not need to be public unless you want them accessed from other classes. For example, the ``created_at ``
203203class property will be accessed through the ``setCreatedAt() `` and ``getCreatedAt() `` methods.
204204
@@ -239,10 +239,10 @@ As an example, imagine you have the simplified User Entity that is used througho
239239 class User extends Entity
240240 {
241241 protected $attributes = [
242- 'id' => null,
243- 'name' => null, // Represents a username
244- 'email' => null,
245- 'password' => null,
242+ 'id' => null,
243+ 'name' => null, // Represents a username
244+ 'email' => null,
245+ 'password' => null,
246246 'created_at' => null,
247247 'updated_at' => null,
248248 ];
@@ -266,10 +266,10 @@ simply map the ``full_name`` column in the database to the ``$name`` property, a
266266 class User extends Entity
267267 {
268268 protected $attributes = [
269- 'id' => null,
270- 'name' => null, // Represents a username
271- 'email' => null,
272- 'password' => null,
269+ 'id' => null,
270+ 'name' => null, // Represents a username
271+ 'email' => null,
272+ 'password' => null,
273273 'created_at' => null,
274274 'updated_at' => null,
275275 ];
@@ -299,7 +299,7 @@ By default, the Entity class will convert fields named `created_at`, `updated_at
299299:doc: `Time </libraries/time >` instances whenever they are set or retrieved. The Time class provides a large number
300300of helpful methods in an immutable, localized way.
301301
302- You can define which properties are automatically converted by adding the name to the ** options[' dates'] ** array ::
302+ You can define which properties are automatically converted by adding the name to the `` $ dates`` property ::
303303
304304 <?php
305305
@@ -327,14 +327,14 @@ current timezone, as set in **app/Config/App.php**::
327327Property Casting
328328----------------
329329
330- You can specify that properties in your Entity should be converted to common data types with the ** casts ** property.
330+ You can specify that properties in your Entity should be converted to common data types with the `` $ casts`` property.
331331This option should be an array where the key is the name of the class property, and the value is the data type it
332332should be cast to. Casting only affects when values are read. No conversions happen that affect the permanent value in
333333either the entity or the database. Properties can be cast to any of the following data types:
334334**integer **, **float **, **double **, **string **, **boolean **, **object **, **array **, **datetime **, **timestamp **, and **uri **.
335335Add a question mark at the beginning of type to mark property as nullable, i.e., **?string **, **?integer **.
336336
337- For example, if you had a User entity with an ** is_banned ** property, you can cast it as a boolean::
337+ For example, if you had a User entity with an `` is_banned `` property, you can cast it as a boolean::
338338
339339 <?php
340340
@@ -356,8 +356,8 @@ Array/Json Casting
356356Array/Json casting is especially useful with fields that store serialized arrays or json in them. When cast as:
357357
358358* an **array **, they will automatically be unserialized,
359- * a **json **, they will automatically be set as an value of json_decode($value, false),
360- * a **json-array **, they will automatically be set as an value of json_decode($value, true),
359+ * a **json **, they will automatically be set as an value of `` json_decode($value, false) `` ,
360+ * a **json-array **, they will automatically be set as an value of `` json_decode($value, true) `` ,
361361
362362when you set the property's value.
363363Unlike the rest of the data types that you can cast properties into, the:
@@ -425,15 +425,15 @@ Custom casting
425425You can define your own conversion types for getting and setting data.
426426
427427At first you need to create a handler class for your type.
428- Let's say the class will be located in the ' app/Entity/Cast' directory::
428+ Let's say the class will be located in the ** app/Entity/Cast ** directory::
429429
430430 <?php
431431
432432 namespace App\Entity\Cast;
433433
434434 use CodeIgniter\Entity\Cast\BaseCast;
435435
436- //The class must inherit the CodeIgniter\Entity\Cast\BaseCast class
436+ // The class must inherit the CodeIgniter\Entity\Cast\BaseCast class
437437 class CastBase64 extends BaseCast
438438 {
439439 public static function get($value, array $params = [])
@@ -462,13 +462,13 @@ Now you need to register it::
462462 'key' => 'base64',
463463 ];
464464
465- //Bind the type to the handler
465+ // Bind the type to the handler
466466 protected $castHandlers = [
467467 'base64' => \App\Entity\Cast\CastBase64::class,
468468 ];
469469 }
470470
471- //...
471+ // ...
472472
473473 $entity->key = 'test'; // dGVzdA==
474474 echo $entity->key; // test
0 commit comments