Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add info about Router::getMatchedRouteOptions() #9441

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions user_guide_src/source/incoming/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
neznaika0 marked this conversation as resolved.
Show resolved Hide resolved

.. literalinclude:: routing/074.php

24 changes: 24 additions & 0 deletions user_guide_src/source/incoming/routing/074.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// Get the router instance.
/** @var \CodeIgniter\Router\Router $router */
$router = service('router');
$options = $router->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
neznaika0 marked this conversation as resolved.
Show resolved Hide resolved
// [offset] => 1
// [priority] => 1
// [as] => api:auth
// [redirect] => 302
neznaika0 marked this conversation as resolved.
Show resolved Hide resolved
// )