In CakePHP 2.x I used this function in beforeRender() at AppController to use custom error page for all kind of error.
/if ($this->name == ‘CakeError’) { $this->layout = ‘front_end_error’; }
How to do this in cakePHP 4.x without changing Debug Level (false) ?
Thanks
Zuluru
2
This seems like it should be handled (maybe even already?) by the error handler middleware, not in beforeRender
.
ADmad
3
I added this
public function beforeRender(EventInterface $event)
{
parent::beforeRender($event);
//$this->viewBuilder()->setTemplatePath('Error');
$this->viewBuilder()->setLayout('error_404'); // layout
}
its not working when i try to enter wrong url like localhost/project/abcd
Now i am getting " Controller class Abcd could not be found.". error instead of error_404 page.
ADmad
5
Test with debug turned off. In debug mode CakePHP will generate developer friendly error pages.
i think a better approach would be to use Cakephp 4 Error handling. Error & Exception Handling - 4.x