Hello everyone,
first thank you for taking time read my post and trying to help me.
I am new in CakePHP and still learning. Worked with another framework before but this is stropped from beeing supprted and I will learn to reprogram my sites in CakePHP.
I started with the tutorial and now I like to improve it to send a user to a forbidden page when he/she is not authorized. The Authorization plugin is workind and a ForbiddenException
is thrown correctly. So far all good.
In my config/routes.php
I am using the following:
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder): void {
// ... some other routes from tutorial
$builder->connect(
'/forbidden',
['controller' => 'Staticpages', 'action' => 'forbidden'],
['_name' => 'forbidden']
);
$builder->fallbacks();
});
in my Application.php
I call the named route by using this:
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
$middlewareQueue
// ... many other middleware by tutorial
->add(new AuthorizationMiddleware($this, [
'unauthorizedHandler' => [
'className' => 'Authorization.CakeRedirect',
'url' => Router::url(['_name' => 'forbidden']),
'queryParam' => 'redirectUrl',
'exceptions' => [
MissingIdentityException::class,
ForbiddenException::class,
],
],
]));
return $middlewareQueue;
}
When I am accessing the page, dont matter wich site, the framework always errors with:
Missing Route
A route matchingforbidden
could not be found.
When using bin\cake routes
(I am using Windows) the route is listed in the table.
I am trying to understand what is going for the last 2 days but I cant find any error.
Thanks for your help!