I get url not exist in router, i can get error 404, but i get error this:
Cake\Routing\Exception\MissingRouteException
and error is 500
I use PHP Cake 5.0.10
Thanks
I get url not exist in router, i can get error 404, but i get error this:
Cake\Routing\Exception\MissingRouteException
and error is 500
I use PHP Cake 5.0.10
Thanks
Are you certain that you get a HTTP Code 500?
Im sorry, in browser console get 404, but call error template error500.php …
Please advise how to display the template, since the page was not found? Or where should this error be resolved?
First of all - you are in debug mode. Maybe try disabling debug mode if you want to style/template the 404 page.
I turned off debug mode, the error in the console is 404 - the error500.php template is loaded
2024-08-07 16:20:05 error: [Cake\Routing\Exception\MissingRouteException] A route matching `/111` could not be found. in F:\server\www.domain.com\vendor\cakephp\cakephp\src\Routing\RouteCollection.php on line 180
Stack Trace:
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Routing\Router.php:197
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php:96
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:82
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Routing\Middleware\AssetMiddleware.php:69
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:82
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Error\Middleware\ErrorHandlerMiddleware.php:115
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:82
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Middleware\HttpsEnforcerMiddleware.php:95
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:82
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Middleware\SecurityHeadersMiddleware.php:258
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:82
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Runner.php:60
- F:\server\\www.domain.com\vendor\cakephp\cakephp\src\Http\Server.php:103
- F:\server\\www.domain.com\webroot\index.php:37
- [main]:
Request URL: /111
Should the error400.php template be loaded?
Thank You, i found problem… in AppController.php have this:
/**
* beforeRender callback.
*
* @param \Cake\Event\EventInterface $event Event.
* @return \Cake\Http\Response|null|void
*/
public function beforeRender(EventInterface $event)
{
$controller = $this->getRequest()->getParam('controller');
$action = $this->getRequest()->getParam('action');
if ($this->request->is('ajax')) {
// https://book.cakephp.org/4/en/controllers.html#using-ajaxview
$this->viewBuilder()->setClassName('Ajax');
} else {
// Layout for manage
if ($this->layout === 'Pages/Manage') {
$this->viewBuilder()->setLayout('manage');
}
// Layout for web
if ($this->layout === 'Pages/Web') {
if ($controller == 'Auth' && $action != 'register') {
$this->viewBuilder()->setLayout('auth');
} else {
$this->viewBuilder()->setLayout('default');
}
}
}
}
If deleted, i get error400.php…
i must edit this…
// Layout for manage
if ($this->layout === 'Pages/Manage') {
$this->viewBuilder()->setLayout('manage');
}
// Layout for web
if ($this->layout === 'Pages/Web') {
if ($controller == 'Auth' && $action != 'register') {
$this->viewBuilder()->setLayout('auth');
} else {
$this->viewBuilder()->setLayout('default');
}
}
Now edit and its works…
/**
* beforeRender callback.
*
* @param \Cake\Event\EventInterface $event Event.
* @return \Cake\Http\Response|null|void
*/
public function beforeRender(EventInterface $event)
{
$controller = $this->getRequest()->getParam('controller');
$action = $this->getRequest()->getParam('action');
$prefix = $this->getRequest()->getParam('prefix');
if ($this->request->is('ajax')) {
// https://book.cakephp.org/4/en/controllers.html#using-ajaxview
$this->viewBuilder()->setClassName('Ajax');
} else {
if ($prefix === 'Pages/Manage') {
$this->viewBuilder()->setLayout('manage');
} elseif ($prefix === 'Pages/Web') {
if ($controller == 'Auth' && $action != 'register') {
$this->viewBuilder()->setLayout('auth');
} else {
$this->viewBuilder()->setLayout('default');
}
} else {
$this->viewBuilder()->setLayout('default'); // Fallback to default layout
}
}
}