Skip to content

Commit

Permalink
style: run composer cs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
datamweb committed Aug 19, 2024
1 parent 919f0df commit 962aecd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
45 changes: 33 additions & 12 deletions user_guide_src/source/incoming/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ a simple view:

.. literalinclude:: routing/020.php

Retrieving the Controller and Method Names
------------------------------------------

In some cases, you might need to determine which controller and method have been triggered by the current HTTP request.
This can be useful for logging, debugging, or conditional logic based on the active controller method.

CodeIgniter 4 provides a simple way to access the current route's controller and method names using the ``Router`` class. Here is an example:

.. literalinclude:: routing/071.php

This functionality is particularly useful when you need to dynamically interact with your controller or log which method is handling a particular request.

Specifying Route Paths
======================

Expand Down Expand Up @@ -1139,3 +1127,36 @@ You can specify the host in the request URL with the ``--host`` option:
.. code-block:: console
php spark routes --host accounts.example.com
Getting Routing Information
***************************

In CodeIgniter 4, understanding and managing routing information is crucial for handling HTTP requests effectively.
This involves retrieving details about the active controller and method, as well as the filters applied to a specific route.
Below, we explore how to access this routing information to assist in tasks such as logging, debugging, or implementing conditional logic.

Retrieving the Controller and Method Names
==========================================

In some cases, you might need to determine which controller and method have been triggered by the current HTTP request.
This can be useful for logging, debugging, or conditional logic based on the active controller method.

CodeIgniter 4 provides a simple way to access the current route's controller and method names using the ``Router`` class. Here is an example:

.. literalinclude:: routing/071.php

This functionality is particularly useful when you need to dynamically interact with your controller or log which method is handling a particular request.

Accessing Active Filters for a Route
====================================

: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.
To access the active filters for a specific route, you can use the :php:meth:`CodeIgniter\\Router\\Router::getFilters()` method from the ``Router`` class.

This method returns a list of filters that are currently active for the route being processed:

.. literalinclude:: routing/072.php

.. note:: The ``getFilters()`` method returns only the filters defined for the specific route.
It does not include global filters or those specified in configuration files.

1 change: 1 addition & 0 deletions user_guide_src/source/incoming/routing/071.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// Get the router instance.
/** @var \CodeIgniter\Router\Router $router */
$router = service('router');
Expand Down
16 changes: 8 additions & 8 deletions user_guide_src/source/incoming/routing/072.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

// Get the router instance.
/** @var \CodeIgniter\Router\Router $router */
$router = service('router');
$filters = $router->getFilters();

echo 'Active Filters for the Route: ' . implode(', ', $filters);
<?php

// Get the router instance.
/** @var \CodeIgniter\Router\Router $router */
$router = service('router');
$filters = $router->getFilters();

echo 'Active Filters for the Route: ' . implode(', ', $filters);

0 comments on commit 962aecd

Please sign in to comment.