CakePHP 2.0 - How to make custom error pages?
Try this:
/app/Config/core.php
Exception render need to set as an AppExceptionRender
. Example:
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'AppExceptionRenderer',
'log' => true
));
/app/Controller/ErrorsController.php
class ErrorsController extends AppController {
public $name = 'Errors';
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('error404');
}
public function error404() {
//$this->layout = 'default';
}
}
/app/Lib/Error/AppExceptionRenderer.php
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
public function notFound($error) {
$this->controller->redirect(array('controller' => 'errors', 'action' => 'error404'));
}
}
/app/View/Errors/error404.ctp
<div class="inner404">
<h2>404 Error - Page Not Found</h2>
</div>
Insert it where you need: throw new NotFoundException();
Cakephp Custom Error pages
With debug turned off all your error are converted to either 400 or 500 errors. So you just need to customize your app/View/Errors/error400.ctp
and app/View/Errors/error500.ctp
as required.
Cakephp error custom page
Try the second answer:
To customize the content of a 404-error page and don't need custom
logic, simply edit the contents of app/View/Errors/error400.ctp.
Note that you need to also set your debug level to zero to see your custom error page.
Custom Error Pages for CakePHP Plugin
I was able to solve this by overloading the the _outputMessage() function within ErrorHandler by saving the following as app/app_error.php
<?php
class AppError extends ErrorHandler {
function _outputMessage( $template ) {
$url = $this->controller->params['url']['url'];
if( substr( $url, 0, 6 ) == 'admin/' ) {
$this->controller->layout = 'admin_default';
}
parent::_outputMessage( $template );
}
}
?>
Cakephp - how to make error pages have its own layouts?
Savant from the IRC helped me out and he suggest in using beforeRender(){}
in the app_controller
// Before Render
function beforeRender() {
if($this->name == 'CakeError') {
//$this->layout = 'error';
}
}
CakeError is a catchAll for errors :D
How to put custom layout in 404 error page instead of default layout in cake php2.x
after doing lots of research finally i get the solution
Change the ExceptionRenderer in core.php to use your own renderer.
app/Config/core.php:
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'MyExceptionRenderer',
'log' => true
));
then create new file MyExceptionRenderer.php
app/Lib/Error/MyExceptionRenderer.php:
<?php
App::uses('ExceptionRenderer', 'Error');
class MyExceptionRenderer extends ExceptionRenderer {
protected function _outputMessage($template) {
$this->controller->layout = 'innerdefault';
parent::_outputMessage($template);
}
}
?>
this works fine for me, lets try and share you thought
Related Topics
Php.Ini Is Nonexistent Loaded Configuration File (None)
Exception: Serialization of 'Closure' Is Not Allowed
How to Replace (Monkeypatch) PHP Functions
Angularjs Upload Multiple Files with Formdata API
Woocommerce: Assigning an Endpoint to a Custom Template in My Account Pages
PHP Send E-Mail with Attachment
Formulas to Calculate Geo Proximity
Checking If All the Array Items Are Empty PHP
How to Catch This Error: "Notice: Undefined Offset: 0"
Executing a Shell Script in Background with PHP
JSON_Encode Function: Special Characters
How to Add All of My Array Values Together in PHP
Populate a Drop Down Box from a MySQL Table in PHP
Laravel Eager Loading with Limit