mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
docs: Add info about Router::getMatchedRouteOptions()
(#9441)
Some checks are pending
Deploy User Guide (latest) / Deploy to gh-pages (push) Waiting to run
AutoReview / Automatic Code Review (push) Waiting to run
AutoReview / Check normalized composer.json (push) Waiting to run
Coding Standards / PHP 8.1 Lint with PHP CS Fixer (push) Waiting to run
Coding Standards / PHP 8.4 Lint with PHP CS Fixer (push) Waiting to run
Check File Permissions / Check File Permission (push) Waiting to run
Psalm / Psalm Analysis (push) Waiting to run
Some checks are pending
Deploy User Guide (latest) / Deploy to gh-pages (push) Waiting to run
AutoReview / Automatic Code Review (push) Waiting to run
AutoReview / Check normalized composer.json (push) Waiting to run
Coding Standards / PHP 8.1 Lint with PHP CS Fixer (push) Waiting to run
Coding Standards / PHP 8.4 Lint with PHP CS Fixer (push) Waiting to run
Check File Permissions / Check File Permission (push) Waiting to run
Psalm / Psalm Analysis (push) Waiting to run
* docs: Add info about `Router::getMatchedRouteOptions()` * fix: Apply suggestions
This commit is contained in:
parent
73d5d3f813
commit
efcabb3fdf
@ -1044,3 +1044,12 @@ 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
|
||||
===================================================
|
||||
|
||||
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
|
||||
|
||||
|
23
user_guide_src/source/incoming/routing/074.php
Normal file
23
user_guide_src/source/incoming/routing/074.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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] => example.com
|
||||
// [subdomain] => api
|
||||
// [offset] => 1
|
||||
// [priority] => 1
|
||||
// [as] => api:auth
|
||||
// )
|
Loading…
x
Reference in New Issue
Block a user