Skip to content

Commit 0cf7d29

Browse files
committed
Update User Guide
1 parent 50a73d6 commit 0cf7d29

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

incoming/routing.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ <h1>URI Routing<a class="headerlink" href="#uri-routing" title="Permalink to thi
394394
<ul>
395395
<li><p><a class="reference internal" href="#retrieving-the-current-controller-method-names" id="id74">Retrieving the Current Controller/Method Names</a></p></li>
396396
<li><p><a class="reference internal" href="#getting-active-filters-for-the-current-route" id="id75">Getting Active Filters for the Current Route</a></p></li>
397+
<li><p><a class="reference internal" href="#getting-matched-route-options-for-the-current-route" id="id76">Getting Matched Route Options for the Current Route</a></p></li>
397398
</ul>
398399
</li>
399400
</ul>
@@ -1747,6 +1748,37 @@ <h3><a class="toc-backref" href="#id75" role="doc-backlink">Getting Active Filte
17471748
It does not include global filters or those specified in the <strong>app/Config/Filters.php</strong> file.</p>
17481749
</div>
17491750
</section>
1751+
<section id="getting-matched-route-options-for-the-current-route">
1752+
<h3><a class="toc-backref" href="#id76" role="doc-backlink">Getting Matched Route Options for the Current Route</a><a class="headerlink" href="#getting-matched-route-options-for-the-current-route" title="Permalink to this heading"></a></h3>
1753+
<p>When we’re defining routes, they may have optional parameters: <code class="docutils literal notranslate"><span class="pre">filter</span></code>, <code class="docutils literal notranslate"><span class="pre">namespace</span></code>, <code class="docutils literal notranslate"><span class="pre">hostname</span></code>, <code class="docutils literal notranslate"><span class="pre">subdomain</span></code>, <code class="docutils literal notranslate"><span class="pre">offset</span></code>, <code class="docutils literal notranslate"><span class="pre">priority</span></code>, <code class="docutils literal notranslate"><span class="pre">as</span></code>. All of them were described earlier above.
1754+
Additionally, if we use <code class="docutils literal notranslate"><span class="pre">addRedirect()</span></code> we can also expect the <code class="docutils literal notranslate"><span class="pre">redirect</span></code> key.
1755+
To access the values of these parameters, we can call <code class="docutils literal notranslate"><span class="pre">Router::getMatchedRouteOptions()</span></code>. Here is an example of the returned array:</p>
1756+
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;?</span><span class="nx">php</span>
1757+
1758+
<span class="c1">// Get the router instance.</span>
1759+
<span class="sd">/** @var \CodeIgniter\Router\Router $router */</span>
1760+
<span class="nv">$router</span> <span class="o">=</span> <span class="nx">service</span><span class="p">(</span><span class="s1">&#39;router&#39;</span><span class="p">);</span>
1761+
<span class="nv">$options</span> <span class="o">=</span> <span class="nv">$router</span><span class="o">-&gt;</span><span class="na">getMatchedRouteOptions</span><span class="p">();</span>
1762+
1763+
<span class="k">echo</span> <span class="s1">&#39;Route name: &#39;</span> <span class="o">.</span> <span class="nv">$options</span><span class="p">[</span><span class="s1">&#39;as&#39;</span><span class="p">];</span>
1764+
1765+
<span class="nb">print_r</span><span class="p">(</span><span class="nv">$options</span><span class="p">);</span>
1766+
1767+
<span class="c1">// Route name: api:auth</span>
1768+
<span class="c1">//</span>
1769+
<span class="c1">// Array</span>
1770+
<span class="c1">// (</span>
1771+
<span class="c1">// [filter] =&gt; api-auth</span>
1772+
<span class="c1">// [namespace] =&gt; App\API\v1</span>
1773+
<span class="c1">// [hostname] =&gt; example.com</span>
1774+
<span class="c1">// [subdomain] =&gt; api</span>
1775+
<span class="c1">// [offset] =&gt; 1</span>
1776+
<span class="c1">// [priority] =&gt; 1</span>
1777+
<span class="c1">// [as] =&gt; api:auth</span>
1778+
<span class="c1">// )</span>
1779+
</pre></div>
1780+
</div>
1781+
</section>
17501782
</section>
17511783
</section>
17521784

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)