mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Update User Guide
This commit is contained in:
parent
55e29c86fb
commit
43a7e0d6ca
@ -351,14 +351,24 @@ but may leave the methods empty if they are not needed. A skeleton filter class
|
||||
</div>
|
||||
<section id="before-filters">
|
||||
<h3><a class="toc-backref" href="#id4">Before Filters</a><a class="headerlink" href="#before-filters" title="Permalink to this headline"></a></h3>
|
||||
<section id="replacing-request">
|
||||
<h4>Replacing Request<a class="headerlink" href="#replacing-request" title="Permalink to this headline"></a></h4>
|
||||
<p>From any filter, you can return the <code class="docutils literal notranslate"><span class="pre">$request</span></code> object and it will replace the current Request, allowing you
|
||||
to make changes that will still be present when the controller executes.</p>
|
||||
<p>Since before filters are executed prior to your controller being executed, you may at times want to stop the
|
||||
actions in the controller from happening. Also, when you have a series of filters you may also want to
|
||||
</section>
|
||||
<section id="stopping-later-filters">
|
||||
<h4>Stopping Later Filters<a class="headerlink" href="#stopping-later-filters" title="Permalink to this headline"></a></h4>
|
||||
<p>Also, when you have a series of filters you may also want to
|
||||
stop the execution of the later filters after a certain filter. You can easily do this by returning
|
||||
<strong>any non-empty</strong> result. If the before filter returns an empty result, the controller actions or the later
|
||||
filters will still be executed. An exception to the non-empty result rule is the <code class="docutils literal notranslate"><span class="pre">Request</span></code> instance.
|
||||
filters will still be executed.</p>
|
||||
<p>An exception to the non-empty result rule is the <code class="docutils literal notranslate"><span class="pre">Request</span></code> instance.
|
||||
Returning it in the before filter will not stop the execution but only replace the current <code class="docutils literal notranslate"><span class="pre">$request</span></code> object.</p>
|
||||
</section>
|
||||
<section id="returning-response">
|
||||
<h4>Returning Response<a class="headerlink" href="#returning-response" title="Permalink to this headline"></a></h4>
|
||||
<p>Since before filters are executed prior to your controller being executed, you may at times want to stop the
|
||||
actions in the controller from happening.</p>
|
||||
<p>This is typically used to perform redirects, like in this example:</p>
|
||||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span>
|
||||
|
||||
@ -385,6 +395,7 @@ Returning it in the before filter will not stop the execution but only replace t
|
||||
This can be useful for implementing rate limiting for APIs. See <a class="reference internal" href="../libraries/throttler.html"><span class="doc">Throttler</span></a> for an
|
||||
example.</p>
|
||||
</section>
|
||||
</section>
|
||||
<section id="after-filters">
|
||||
<span id="id1"></span><h3><a class="toc-backref" href="#id5">After Filters</a><a class="headerlink" href="#after-filters" title="Permalink to this headline"></a></h3>
|
||||
<p>After filters are nearly identical to before filters, except that you can only return the <code class="docutils literal notranslate"><span class="pre">$response</span></code> object,
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user