Update User Guide

This commit is contained in:
MGatner 2021-05-11 11:33:51 +00:00
parent 186845e5f0
commit 83198b74ff
4 changed files with 52 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -621,6 +621,20 @@ specified header object in a case-insensitive manner if it exists. If not, then
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-&gt;</span><span class="na">getTotalSegments</span><span class="p">();</span> <span class="c1">// 3</span>
</pre></div>
</div>
<p>You can work with the current URI string (the path relative to your baseURL) using the <code class="docutils literal notranslate"><span class="pre">getPath()</span></code> and <code class="docutils literal notranslate"><span class="pre">setPath()</span></code> methods.
Note that this relative path on the shared instance of <code class="docutils literal notranslate"><span class="pre">IncomingRequest</span></code> is what the <a class="reference internal" href="../helpers/url_helper.html"><span class="doc">URL Helper</span></a>
functions use, so this is a helpful way to “spoof” an incoming request for testing:</p>
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyMenuTest</span> <span class="k">extends</span> <span class="nx">CIUnitTestCase</span>
<span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">testActiveLinkUsesCurrentUrl</span><span class="p">()</span>
<span class="p">{</span>
<span class="nx">service</span><span class="p">(</span><span class="s1">&#39;request&#39;</span><span class="p">)</span><span class="o">-&gt;</span><span class="na">setPath</span><span class="p">(</span><span class="s1">&#39;users/list&#39;</span><span class="p">);</span>
<span class="nv">$menu</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">MyMenu</span><span class="p">();</span>
<span class="nv">$this</span><span class="o">-&gt;</span><span class="na">assertTrue</span><span class="p">(</span><span class="s1">&#39;users/list&#39;</span><span class="p">,</span> <span class="nv">$menu</span><span class="o">-&gt;</span><span class="na">getActiveLink</span><span class="p">());</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="uploaded-files">
<h2><a class="toc-backref" href="#id6">Uploaded Files</a><a class="headerlink" href="#uploaded-files" title="Permalink to this headline"></a></h2>
@ -986,6 +1000,42 @@ found <a class="reference external" href="https://www.php.net/manual/en/filter.f
</div>
</dd></dl>
<dl class="method">
<dt id="getPath">
<code class="sig-name descname">getPath</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#getPath" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The current URI path relative to <code class="docutils literal notranslate"><span class="pre">$_SERVER['SCRIPT_NAME']</span></code></p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>string</p>
</dd>
</dl>
<p>This is the safest method to determine the “current URI”, since <code class="docutils literal notranslate"><span class="pre">IncomingRequest::$uri</span></code>
may not be aware of the complete App configuration for base URLs.</p>
</dd></dl>
<dl class="method">
<dt id="setPath">
<code class="sig-name descname">setPath</code><span class="sig-paren">(</span><em class="sig-param">$path</em><span class="sig-paren">)</span><a class="headerlink" href="#setPath" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>$path</strong> (<em>string</em>) The relative path to use as the current URI</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>This Incoming Request</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>IncomingRequest</p>
</dd>
</dl>
<p>Used mostly just for testing purposes, this allows you to set the relative path
value for the current request instead of relying on URI detection. This will also
update the underlying <code class="docutils literal notranslate"><span class="pre">URI</span></code> instance with the new path.</p>
</dd></dl>
</dd></dl>
</div>

Binary file not shown.

File diff suppressed because one or more lines are too long