5
* Provides Error Capturing for Framework errors.
9
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
10
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
12
* Licensed under The MIT License
13
* Redistributions of files must retain the above copyright notice.
15
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
16
* @link http://cakephp.org CakePHP(tm) Project
18
* @subpackage cake.cake.libs
19
* @since CakePHP(tm) v 0.10.5.1732
20
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
22
App::import('Controller', 'App');
25
* Error Handling Controller
27
* Controller used by ErrorHandler to render error views.
30
* @subpackage cake.cake.libs
32
class CakeErrorController extends AppController {
33
var $name = 'CakeError';
48
function __construct() {
49
parent::__construct();
50
$this->_set(Router::getPaths());
51
$this->params = Router::getParams();
52
$this->constructClasses();
53
$this->Component->initialize($this);
54
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
61
* Captures and handles all cakeError() calls.
62
* Displays helpful framework errors when debug > 1.
63
* When debug < 1 cakeError() will render 404 or 500 errors.
66
* @subpackage cake.cake.libs
68
class ErrorHandler extends Object {
71
* Controller instance.
76
var $controller = null;
81
* @param string $method Method producing the error
82
* @param array $messages Error messages
84
function __construct($method, $messages) {
85
App::import('Core', 'Sanitize');
86
static $__previousError = null;
88
if ($__previousError != array($method, $messages)) {
89
$__previousError = array($method, $messages);
90
$this->controller =& new CakeErrorController();
92
$this->controller =& new Controller();
93
$this->controller->viewPath = 'errors';
95
$options = array('escape' => false);
96
$messages = Sanitize::clean($messages, $options);
98
if (!isset($messages[0])) {
99
$messages = array($messages);
102
if (method_exists($this->controller, 'apperror')) {
103
return $this->controller->appError($method, $messages);
106
if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
110
if ($method !== 'error') {
111
if (Configure::read('debug') == 0) {
112
$parentClass = get_parent_class($this);
113
if (strtolower($parentClass) != 'errorhandler') {
114
$method = 'error404';
116
$parentMethods = array_map('strtolower', get_class_methods($parentClass));
117
if (in_array(strtolower($method), $parentMethods)) {
118
$method = 'error404';
120
if (isset($messages[0]['code']) && $messages[0]['code'] == 500) {
121
$method = 'error500';
125
$this->dispatchMethod($method, $messages);
130
* Displays an error page (e.g. 404 Not found).
132
* @param array $params Parameters for controller
135
function error($params) {
136
extract($params, EXTR_OVERWRITE);
137
$this->controller->set(array(
140
'message' => $message,
141
'title' => $code . ' ' . $name
143
$this->_outputMessage('error404');
147
* Convenience method to display a 404 page.
149
* @param array $params Parameters for controller
152
function error404($params) {
153
extract($params, EXTR_OVERWRITE);
156
$url = $this->controller->here;
158
$url = Router::normalize($url);
159
$this->controller->header("HTTP/1.0 404 Not Found");
160
$this->controller->set(array(
162
'name' => __('Not Found', true),
163
'message' => h($url),
164
'base' => $this->controller->base
166
$this->_outputMessage('error404');
170
* Convenience method to display a 500 page.
172
* @param array $params Parameters for controller
175
function error500($params) {
176
extract($params, EXTR_OVERWRITE);
179
$url = $this->controller->here;
181
$url = Router::normalize($url);
182
$this->controller->header("HTTP/1.0 500 Internal Server Error");
183
$this->controller->set(array(
185
'name' => __('An Internal Error Has Occurred', true),
186
'message' => h($url),
187
'base' => $this->controller->base
189
$this->_outputMessage('error500');
192
* Renders the Missing Controller web page.
194
* @param array $params Parameters for controller
197
function missingController($params) {
198
extract($params, EXTR_OVERWRITE);
200
$controllerName = str_replace('Controller', '', $className);
201
$this->controller->set(array(
202
'controller' => $className,
203
'controllerName' => $controllerName,
204
'title' => __('Missing Controller', true)
206
$this->_outputMessage('missingController');
210
* Renders the Missing Action web page.
212
* @param array $params Parameters for controller
215
function missingAction($params) {
216
extract($params, EXTR_OVERWRITE);
218
$controllerName = str_replace('Controller', '', $className);
219
$this->controller->set(array(
220
'controller' => $className,
221
'controllerName' => $controllerName,
223
'title' => __('Missing Method in Controller', true)
225
$this->_outputMessage('missingAction');
229
* Renders the Private Action web page.
231
* @param array $params Parameters for controller
234
function privateAction($params) {
235
extract($params, EXTR_OVERWRITE);
237
$this->controller->set(array(
238
'controller' => $className,
240
'title' => __('Trying to access private method in class', true)
242
$this->_outputMessage('privateAction');
246
* Renders the Missing Table web page.
248
* @param array $params Parameters for controller
251
function missingTable($params) {
252
extract($params, EXTR_OVERWRITE);
254
$this->controller->header("HTTP/1.0 500 Internal Server Error");
255
$this->controller->set(array(
257
'model' => $className,
259
'title' => __('Missing Database Table', true)
261
$this->_outputMessage('missingTable');
265
* Renders the Missing Database web page.
267
* @param array $params Parameters for controller
270
function missingDatabase($params = array()) {
271
$this->controller->header("HTTP/1.0 500 Internal Server Error");
272
$this->controller->set(array(
274
'title' => __('Scaffold Missing Database Connection', true)
276
$this->_outputMessage('missingScaffolddb');
280
* Renders the Missing View web page.
282
* @param array $params Parameters for controller
285
function missingView($params) {
286
extract($params, EXTR_OVERWRITE);
288
$this->controller->set(array(
289
'controller' => $className,
292
'title' => __('Missing View', true)
294
$this->_outputMessage('missingView');
298
* Renders the Missing Layout web page.
300
* @param array $params Parameters for controller
303
function missingLayout($params) {
304
extract($params, EXTR_OVERWRITE);
306
$this->controller->layout = 'default';
307
$this->controller->set(array(
309
'title' => __('Missing Layout', true)
311
$this->_outputMessage('missingLayout');
315
* Renders the Database Connection web page.
317
* @param array $params Parameters for controller
320
function missingConnection($params) {
321
extract($params, EXTR_OVERWRITE);
323
$this->controller->header("HTTP/1.0 500 Internal Server Error");
324
$this->controller->set(array(
326
'model' => $className,
327
'title' => __('Missing Database Connection', true)
329
$this->_outputMessage('missingConnection');
333
* Renders the Missing Helper file web page.
335
* @param array $params Parameters for controller
338
function missingHelperFile($params) {
339
extract($params, EXTR_OVERWRITE);
341
$this->controller->set(array(
342
'helperClass' => Inflector::camelize($helper) . "Helper",
344
'title' => __('Missing Helper File', true)
346
$this->_outputMessage('missingHelperFile');
350
* Renders the Missing Helper class web page.
352
* @param array $params Parameters for controller
355
function missingHelperClass($params) {
356
extract($params, EXTR_OVERWRITE);
358
$this->controller->set(array(
359
'helperClass' => Inflector::camelize($helper) . "Helper",
361
'title' => __('Missing Helper Class', true)
363
$this->_outputMessage('missingHelperClass');
367
* Renders the Missing Behavior file web page.
369
* @param array $params Parameters for controller
372
function missingBehaviorFile($params) {
373
extract($params, EXTR_OVERWRITE);
375
$this->controller->set(array(
376
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
378
'title' => __('Missing Behavior File', true)
380
$this->_outputMessage('missingBehaviorFile');
384
* Renders the Missing Behavior class web page.
386
* @param array $params Parameters for controller
389
function missingBehaviorClass($params) {
390
extract($params, EXTR_OVERWRITE);
392
$this->controller->set(array(
393
'behaviorClass' => Inflector::camelize($behavior) . "Behavior",
395
'title' => __('Missing Behavior Class', true)
397
$this->_outputMessage('missingBehaviorClass');
401
* Renders the Missing Component file web page.
403
* @param array $params Parameters for controller
406
function missingComponentFile($params) {
407
extract($params, EXTR_OVERWRITE);
409
$this->controller->set(array(
410
'controller' => $className,
411
'component' => $component,
413
'title' => __('Missing Component File', true)
415
$this->_outputMessage('missingComponentFile');
419
* Renders the Missing Component class web page.
421
* @param array $params Parameters for controller
424
function missingComponentClass($params) {
425
extract($params, EXTR_OVERWRITE);
427
$this->controller->set(array(
428
'controller' => $className,
429
'component' => $component,
431
'title' => __('Missing Component Class', true)
433
$this->_outputMessage('missingComponentClass');
437
* Renders the Missing Model class web page.
439
* @param unknown_type $params Parameters for controller
442
function missingModel($params) {
443
extract($params, EXTR_OVERWRITE);
445
$this->controller->set(array(
446
'model' => $className,
447
'title' => __('Missing Model', true)
449
$this->_outputMessage('missingModel');
457
function _outputMessage($template) {
458
$this->controller->render($template);
459
$this->controller->afterFilter();
460
echo $this->controller->output;