Skip to content

Commit d5b08ff

Browse files
authored
Merge pull request #304 from cakephp/3.x-controller-middleware
Controller Usage
2 parents 7f0057d + 977bfd1 commit d5b08ff

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/en/request-authorization-middleware.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,29 @@ AuthorizationMiddleware::
7878
$middlewareQueue->add(new AuthorizationMiddleware($this));
7979
$middlewareQueue->add(new RequestAuthorizationMiddleware());
8080
}
81+
82+
Controller Usage
83+
================
84+
85+
When having fallback routing activated, all asset based 404s as well as not existing controllers would also
86+
trigger the RequestAuthorizationMiddleware.
87+
In this case, it is possible to use this middleware only for your (App)controller::
88+
89+
// src/Controller/AppController.php
90+
public function initialize(): void
91+
{
92+
parent::initialize();
93+
94+
$this->middleware(function ($request, $handler): ResponseInterface {
95+
$config = [
96+
'unauthorizedHandler' => [
97+
...
98+
],
99+
];
100+
$middleware = new RequestAuthorizationMiddleware($config);
101+
102+
return $middleware->process($request, $handler);
103+
});
104+
}
105+
106+
Also note, that in this case you will e.g. need ``'DebugKit.ignoreAuthorization'`` set to ``true``.

0 commit comments

Comments
 (0)