Skip to content

Commit 962aecd

Browse files
committed
style: run composer cs-fix
1 parent 919f0df commit 962aecd

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

user_guide_src/source/incoming/routing.rst

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ a simple view:
151151

152152
.. literalinclude:: routing/020.php
153153

154-
Retrieving the Controller and Method Names
155-
------------------------------------------
156-
157-
In some cases, you might need to determine which controller and method have been triggered by the current HTTP request.
158-
This can be useful for logging, debugging, or conditional logic based on the active controller method.
159-
160-
CodeIgniter 4 provides a simple way to access the current route's controller and method names using the ``Router`` class. Here is an example:
161-
162-
.. literalinclude:: routing/071.php
163-
164-
This functionality is particularly useful when you need to dynamically interact with your controller or log which method is handling a particular request.
165-
166154
Specifying Route Paths
167155
======================
168156

@@ -1139,3 +1127,36 @@ You can specify the host in the request URL with the ``--host`` option:
11391127
.. code-block:: console
11401128
11411129
php spark routes --host accounts.example.com
1130+
1131+
Getting Routing Information
1132+
***************************
1133+
1134+
In CodeIgniter 4, understanding and managing routing information is crucial for handling HTTP requests effectively.
1135+
This involves retrieving details about the active controller and method, as well as the filters applied to a specific route.
1136+
Below, we explore how to access this routing information to assist in tasks such as logging, debugging, or implementing conditional logic.
1137+
1138+
Retrieving the Controller and Method Names
1139+
==========================================
1140+
1141+
In some cases, you might need to determine which controller and method have been triggered by the current HTTP request.
1142+
This can be useful for logging, debugging, or conditional logic based on the active controller method.
1143+
1144+
CodeIgniter 4 provides a simple way to access the current route's controller and method names using the ``Router`` class. Here is an example:
1145+
1146+
.. literalinclude:: routing/071.php
1147+
1148+
This functionality is particularly useful when you need to dynamically interact with your controller or log which method is handling a particular request.
1149+
1150+
Accessing Active Filters for a Route
1151+
====================================
1152+
1153+
:doc:`Filters <filters>` are a powerful feature that enables you to perform operations such as authentication, logging, and security checks before or after processing HTTP requests.
1154+
To access the active filters for a specific route, you can use the :php:meth:`CodeIgniter\\Router\\Router::getFilters()` method from the ``Router`` class.
1155+
1156+
This method returns a list of filters that are currently active for the route being processed:
1157+
1158+
.. literalinclude:: routing/072.php
1159+
1160+
.. note:: The ``getFilters()`` method returns only the filters defined for the specific route.
1161+
It does not include global filters or those specified in configuration files.
1162+

user_guide_src/source/incoming/routing/071.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
// Get the router instance.
34
/** @var \CodeIgniter\Router\Router $router */
45
$router = service('router');
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php
2-
3-
// Get the router instance.
4-
/** @var \CodeIgniter\Router\Router $router */
5-
$router = service('router');
6-
$filters = $router->getFilters();
7-
8-
echo 'Active Filters for the Route: ' . implode(', ', $filters);
1+
<?php
2+
3+
// Get the router instance.
4+
/** @var \CodeIgniter\Router\Router $router */
5+
$router = service('router');
6+
$filters = $router->getFilters();
7+
8+
echo 'Active Filters for the Route: ' . implode(', ', $filters);

0 commit comments

Comments
 (0)