Skip to content

Commit 62c48ac

Browse files
authored
Merge pull request #9002 from kenjis/docs-improve-filters
docs: improve descriptions to Filters
2 parents 42801aa + 9a9a9a0 commit 62c48ac

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

user_guide_src/source/incoming/filters.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Configuring Filters
8282
There are two ways to configure filters when they get run. One is done in
8383
**app/Config/Filters.php**, the other is done in **app/Config/Routes.php**.
8484

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**
8686
and see :ref:`URI Routing <applying-filters>`.
8787

8888
.. 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.
9595

9696
.. Warning:: It is recommended that you should always add ``*`` at the end of a URI in the filter settings.
9797
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()``,
9999
it can be accessible with ``blog``, ``blog/index``, and ``blog/index/1``, etc.
100100

101+
.. _filters-aliases:
102+
101103
$aliases
102104
--------
103105

@@ -106,7 +108,9 @@ filters to run:
106108

107109
.. literalinclude:: filters/003.php
108110

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
110114
in this way makes it simple to switch out the class used. Great for when you decided you need to change to a
111115
different authentication system since you only change the filter's class and you're done.
112116

@@ -170,7 +174,7 @@ an array with the ``except`` key and a URI path (relative to BaseURL) to match a
170174
and the URI paths specified in the filter could be different.
171175
See :ref:`upgrade-447-filter-paths` for details.
172176

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
174178
an asterisk (``*``) for a wildcard that will match all characters after that. In this example, any URI path starting with ``api/``
175179
would be exempted from CSRF protection, but the site's forms would all be protected.
176180

@@ -186,17 +190,19 @@ $methods
186190
because :ref:`auto-routing-legacy` permits any HTTP method to access a controller.
187191
Accessing the controller with a method you don't expect could bypass the filter.
188192

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:
191195

192196
.. literalinclude:: filters/008.php
193197

194198
.. note:: Unlike the ``$globals`` or the
195199
``$filters`` properties, these will only run as before filters.
196200

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
198202
all requests that were run from the command line.
199203

204+
.. note:: Prior to v4.5.0, due to a bug, you needed to specify the HTTP method names in **lowercase**.
205+
200206
$filters
201207
--------
202208

user_guide_src/source/incoming/routing.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,13 @@ Applying Filters
388388
================
389389

390390
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+
391392
The value for the filter can be a string or an array of strings:
392393

393394
* matching the aliases defined in **app/Config/Filters.php**.
394395
* filter classnames
395396

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.
397398

398399
.. Warning:: If you set filters to routes in **app/Config/Routes.php**
399400
(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
405406
Alias Filter
406407
------------
407408

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:
409410

410411
.. literalinclude:: routing/034.php
411412

@@ -418,7 +419,7 @@ Classname Filter
418419

419420
.. versionadded:: 4.1.5
420421

421-
You specify a filter classname for the filter value:
422+
You can specify a filter classname for the filter value:
422423

423424
.. literalinclude:: routing/036.php
424425

@@ -435,7 +436,7 @@ Multiple Filters
435436
:ref:`Upgrading from 4.1.4 to 4.1.5 <upgrade-415-multiple-filters-for-a-route>`
436437
for the details.
437438

438-
You specify an array for the filter value:
439+
You can specify an array for the filter value:
439440

440441
.. literalinclude:: routing/037.php
441442

0 commit comments

Comments
 (0)