Skip to content

Commit 90baec3

Browse files
committed
docs: Add info about Router::getMatchedRouteOptions()
1 parent e89ef62 commit 90baec3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

user_guide_src/source/incoming/routing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,11 @@ This method returns a list of filters that are currently active for the route be
10441044
.. note:: The ``getFilters()`` method returns only the filters defined for the specific route.
10451045
It does not include global filters or those specified in the **app/Config/Filters.php** file.
10461046

1047+
Getting Matched Route Options for the Current Route
1048+
===================================================
1049+
1050+
After creating a route, it may have additional parameters (they are described above): ``filter``, ``namespace``, ``hostname``, ``subdomain``, ``offset``, ``priority``, ``as``, ``redirect``.
1051+
To access these parameters, call ``Router::getMatchedRouteOptions()``. Example of the returned array:
1052+
1053+
.. literalinclude:: routing/074.php
1054+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
// Get the router instance.
4+
/** @var \CodeIgniter\Router\Router $router */
5+
$router = service('router');
6+
$options = $router->getMatchedRouteOptions();
7+
8+
echo 'Route name: ' . $options['as'];
9+
10+
print_r($options);
11+
12+
// Route name: api:auth
13+
//
14+
// Array
15+
// (
16+
// [filter] => api-auth
17+
// [namespace] => App\API\v1
18+
// [hostname] => accounts.example.com
19+
// [subdomain] => media
20+
// [offset] => 1
21+
// [priority] => 1
22+
// [as] => api:auth
23+
// [redirect] => 302
24+
// )

0 commit comments

Comments
 (0)