Wednesday, November 24, 2010

Can AppError be outsourced to a plugin? --psybear

Hi everybody

I have created a small custom ErrorHandler which I'd like to share
between projects. Sadly I'm not too lucky getting it to work as a
plugin. I have only these 3 files so far (the main purpose for my
error handler is that it dislays errors not in the default layout but
in its own error layout).

// app/plugins/plain_error_handler/plain_error_handler_app_error.php
<?php
class PlainErrorHandlerAppError extends ErrorHandler {
function _outputMessage($template) {
$this->controller->layout = 'error';
parent::_outputMessage($template);
}

function error401($params) {
header('HTTP/1.1 401 Unauthorized');
$this->controller->set('message', $params['message']);
$this->_outputMessage('error401');
}
}
?>

// app/plugins/plain_error_handler/views/errors/error401.ctp
<h2>401 - Not authorized</h2>
<p class="error">
<strong><?php __('Error'); ?>: </strong>
<?php echo $message ?>
</p>

// app/plugins/plain_error_handler/views/layouts/error.ctp
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>A fatal error occured</title>
</head>
<body>
<?php echo $content_for_layout; ?>
</body>
</html>

Sadly the files don't seem to be recognized by CakePHP. Do I have to
manually load them somehow? Or can't AppError be outsourced to a
plugin?

Thanks for help
Josh

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: