Update User Guide

This commit is contained in:
kenjis 2023-11-27 23:35:45 +00:00
parent 1b806264e6
commit 0af5c2613c
2 changed files with 13 additions and 5 deletions

View File

@ -282,7 +282,7 @@
<section id="using-entity-classes">
<h1>Using Entity Classes<a class="headerlink" href="#using-entity-classes" title="Permalink to this headline"></a></h1>
<p>CodeIgniter supports Entity classes as a first-class citizen in its database layer, while keeping
<p>CodeIgniter supports Entity classes as a first-class citizen, while keeping
them completely optional to use. They are commonly used as part of the Repository pattern, but can
be used directly with the <a class="reference internal" href="model.html"><span class="doc">Model</span></a> if that fits your needs better.</p>
<div class="contents local topic" id="contents">
@ -315,9 +315,17 @@ be used directly with the <a class="reference internal" href="model.html"><span
<h2><a class="toc-backref" href="#id1">Entity Usage</a><a class="headerlink" href="#entity-usage" title="Permalink to this headline"></a></h2>
<p>At its core, an Entity class is simply a class that represents a single database row. It has class properties
to represent the database columns, and provides any additional methods to implement the business logic for
that row. The core feature, though, is that it doesnt know anything about how to persist itself. Thats the
that row.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>For ease of understanding, the explanation here is based on the case of
using a database. However, Entity can also be used for data that does not come
from a database.</p>
</div>
<p>The core feature, though, is that it doesnt know anything about how to persist itself. Thats the
responsibility of the model or the repository class. That way, if anything changes on how you need to save the
object, you dont have to change how that object is used throughout the application. This makes it possible to
object, you dont have to change how that object is used throughout the application.</p>
<p>This makes it possible to
use JSON or XML files to store the objects during a rapid prototyping stage, and then easily switch to a
database when youve proven the concept works.</p>
<p>Lets walk through a very simple User Entity and how wed work with it to help make things clear.</p>
@ -411,7 +419,7 @@ well as providing the ability to check the properties with <code class="docutils
of what columns have changed since the object was created or pulled from the database.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The Entity class stores the data in the property <code class="docutils literal notranslate"><span class="pre">$attributes</span></code>.</p>
<p>The Entity class stores the data in the class property <code class="docutils literal notranslate"><span class="pre">$attributes</span></code> internally.</p>
</div>
<p>When the User is passed to the models <code class="docutils literal notranslate"><span class="pre">save()</span></code> method, it automatically takes care of reading the properties
and saving any changes to columns listed in the models <code class="docutils literal notranslate"><span class="pre">$allowedFields</span></code> property. It also knows whether to create

File diff suppressed because one or more lines are too long