From 90baec3257ef16bb85f6f7889517b298a5e075c4 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Tue, 4 Feb 2025 22:48:23 +0300 Subject: [PATCH 1/2] docs: Add info about `Router::getMatchedRouteOptions()` --- user_guide_src/source/incoming/routing.rst | 8 +++++++ .../source/incoming/routing/074.php | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 user_guide_src/source/incoming/routing/074.php diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index c2f5977384a2..eb75c6004925 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -1044,3 +1044,11 @@ This method returns a list of filters that are currently active for the route be .. note:: The ``getFilters()`` method returns only the filters defined for the specific route. It does not include global filters or those specified in the **app/Config/Filters.php** file. +Getting Matched Route Options for the Current Route +=================================================== + +After creating a route, it may have additional parameters (they are described above): ``filter``, ``namespace``, ``hostname``, ``subdomain``, ``offset``, ``priority``, ``as``, ``redirect``. +To access these parameters, call ``Router::getMatchedRouteOptions()``. Example of the returned array: + +.. literalinclude:: routing/074.php + diff --git a/user_guide_src/source/incoming/routing/074.php b/user_guide_src/source/incoming/routing/074.php new file mode 100644 index 000000000000..f79b2f32d655 --- /dev/null +++ b/user_guide_src/source/incoming/routing/074.php @@ -0,0 +1,24 @@ +getMatchedRouteOptions(); + +echo 'Route name: ' . $options['as']; + +print_r($options); + +// Route name: api:auth +// +// Array +// ( +// [filter] => api-auth +// [namespace] => App\API\v1 +// [hostname] => accounts.example.com +// [subdomain] => media +// [offset] => 1 +// [priority] => 1 +// [as] => api:auth +// [redirect] => 302 +// ) From 08033f987a6761457b5468058883f4628e85a20f Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Wed, 5 Feb 2025 17:59:56 +0300 Subject: [PATCH 2/2] fix: Apply suggestions --- user_guide_src/source/incoming/routing.rst | 5 +++-- user_guide_src/source/incoming/routing/074.php | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst index eb75c6004925..a1bb81726b14 100644 --- a/user_guide_src/source/incoming/routing.rst +++ b/user_guide_src/source/incoming/routing.rst @@ -1047,8 +1047,9 @@ This method returns a list of filters that are currently active for the route be Getting Matched Route Options for the Current Route =================================================== -After creating a route, it may have additional parameters (they are described above): ``filter``, ``namespace``, ``hostname``, ``subdomain``, ``offset``, ``priority``, ``as``, ``redirect``. -To access these parameters, call ``Router::getMatchedRouteOptions()``. Example of the returned array: +When we're defining routes, they may have optional parameters: ``filter``, ``namespace``, ``hostname``, ``subdomain``, ``offset``, ``priority``, ``as``. All of them were described earlier above. +Additionally, if we use ``addRedirect()`` we can also expect the ``redirect`` key. +To access the values of these parameters, we can call ``Router::getMatchedRouteOptions()``. Here is an example of the returned array: .. literalinclude:: routing/074.php diff --git a/user_guide_src/source/incoming/routing/074.php b/user_guide_src/source/incoming/routing/074.php index f79b2f32d655..74eaeaf7e353 100644 --- a/user_guide_src/source/incoming/routing/074.php +++ b/user_guide_src/source/incoming/routing/074.php @@ -15,10 +15,9 @@ // ( // [filter] => api-auth // [namespace] => App\API\v1 -// [hostname] => accounts.example.com -// [subdomain] => media +// [hostname] => example.com +// [subdomain] => api // [offset] => 1 // [priority] => 1 // [as] => api:auth -// [redirect] => 302 // )