Skip to content

Commit a969827

Browse files
committed
docs: add Retrieving the Controller and Method Names
1 parent f2e560f commit a969827

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

user_guide_src/source/incoming/routing.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ 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 ``Services::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+
154166
Specifying Route Paths
155167
======================
156168

0 commit comments

Comments
 (0)