You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/incoming/filters.rst
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ Configuring Filters
82
82
There are two ways to configure filters when they get run. One is done in
83
83
**app/Config/Filters.php**, the other is done in **app/Config/Routes.php**.
84
84
85
-
If you want to specify filter to a specific route, use **app/Config/Routes.php**
85
+
If you want to specify filters to defined routes, use **app/Config/Routes.php**
86
86
and see :ref:`URI Routing <applying-filters>`.
87
87
88
88
.. Note:: The safest way to apply filters is to :ref:`disable auto-routing <use-defined-routes-only>`, and :ref:`set filters to routes <applying-filters>`.
@@ -95,9 +95,11 @@ configure exactly when the filters run.
95
95
96
96
.. Warning:: It is recommended that you should always add ``*`` at the end of a URI in the filter settings.
97
97
Because a controller method might be accessible by different URLs than you think.
98
-
For example, when :ref:`auto-routing-legacy` is enabled, if you have ``Blog::index``,
98
+
For example, when :ref:`auto-routing-legacy` is enabled, if you have ``Blog::index()``,
99
99
it can be accessible with ``blog``, ``blog/index``, and ``blog/index/1``, etc.
100
100
101
+
.. _filters-aliases:
102
+
101
103
$aliases
102
104
--------
103
105
@@ -106,7 +108,9 @@ filters to run:
106
108
107
109
.. literalinclude:: filters/003.php
108
110
109
-
Aliases are mandatory and if you try to use a full class name later, the system will throw an error. Defining them
111
+
Aliases are mandatory and if you try to use a full class name later, the system will throw an error.
112
+
113
+
Defining them
110
114
in this way makes it simple to switch out the class used. Great for when you decided you need to change to a
111
115
different authentication system since you only change the filter's class and you're done.
112
116
@@ -170,7 +174,7 @@ an array with the ``except`` key and a URI path (relative to BaseURL) to match a
170
174
and the URI paths specified in the filter could be different.
171
175
See :ref:`upgrade-447-filter-paths` for details.
172
176
173
-
Any place you can use a URI path (relative to BaseURL) in the filter settings, you can use a regular expression or, like in this example, use
177
+
Any place you can use a URI path (relative to BaseURL) in the filter settings, you can use a regular expression or, like in this example above, use
174
178
an asterisk (``*``) for a wildcard that will match all characters after that. In this example, any URI path starting with ``api/``
175
179
would be exempted from CSRF protection, but the site's forms would all be protected.
176
180
@@ -186,17 +190,19 @@ $methods
186
190
because :ref:`auto-routing-legacy` permits any HTTP method to access a controller.
187
191
Accessing the controller with a method you don't expect could bypass the filter.
188
192
189
-
You can apply filters to all requests of a certain HTTP method, like POST, GET, PUT, etc. In this array, you would
190
-
specify the method name in **lowercase**. It's value would be an array of filters to run:
193
+
You can apply filters to all requests of a certain HTTP method, like ``POST``, ``GET``, ``PUT``, etc.
194
+
It's value would be an array of filters to run:
191
195
192
196
.. literalinclude:: filters/008.php
193
197
194
198
.. note:: Unlike the ``$globals`` or the
195
199
``$filters`` properties, these will only run as before filters.
196
200
197
-
In addition to the standard HTTP methods, this also supports one special case: ``cli``. The ``cli`` method would apply to
201
+
In addition to the standard HTTP methods, this also supports one special case: ``CLI``. The ``CLI`` method would apply to
198
202
all requests that were run from the command line.
199
203
204
+
.. note:: Prior to v4.5.0, due to a bug, you needed to specify the HTTP method names in **lowercase**.
Copy file name to clipboardExpand all lines: user_guide_src/source/incoming/routing.rst
+5-4Lines changed: 5 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -388,12 +388,13 @@ Applying Filters
388
388
================
389
389
390
390
You can alter the behavior of specific routes by supplying filters to run before or after the controller. This is especially handy during authentication or api logging.
391
+
391
392
The value for the filter can be a string or an array of strings:
392
393
393
394
* matching the aliases defined in **app/Config/Filters.php**.
394
395
* filter classnames
395
396
396
-
See :doc:`Controller Filters <filters>` for more information on setting up filters.
397
+
See :ref:`Controller Filters <filters-aliases>` for more information on defining aliases.
397
398
398
399
.. Warning:: If you set filters to routes in **app/Config/Routes.php**
399
400
(not in **app/Config/Filters.php**), it is recommended to disable Auto Routing (Legacy).
@@ -405,7 +406,7 @@ See :doc:`Controller Filters <filters>` for more information on setting up filte
405
406
Alias Filter
406
407
------------
407
408
408
-
You specify an alias defined in **app/Config/Filters.php** for the filter value:
409
+
You specify an alias :ref:`defined in app/Config/Filters.php<filters-aliases>` for the filter value:
409
410
410
411
.. literalinclude:: routing/034.php
411
412
@@ -418,7 +419,7 @@ Classname Filter
418
419
419
420
.. versionadded:: 4.1.5
420
421
421
-
You specify a filter classname for the filter value:
422
+
You can specify a filter classname for the filter value:
422
423
423
424
.. literalinclude:: routing/036.php
424
425
@@ -435,7 +436,7 @@ Multiple Filters
435
436
:ref:`Upgrading from 4.1.4 to 4.1.5 <upgrade-415-multiple-filters-for-a-route>`
0 commit comments