この記事の所要時間: 約 1分50秒
cakeError()は値を返さない、という話です。
Well, this solution would work fine as long as it is only used internally (even though it is not very elegant). But the framework allows you to write a custom error handler, and so if you want to handle a “missing helper file” error yourself, you get PHP errors when you don’t use an exit.
はじめてこの箇所のコードを追っかけた時にちょっと頭が「?」になりました。エントリでも言及されていますが、自分でエラーハンドラを作る際はこれを意識しておかないとまずい事になりますね。
どうせErrorHandlerでexitするなら、単純にcakeError()は値を返さず、メソッド内でexitすれば良いような気もします。コードで書くとこんな感じですね。
エラー呼び出し元
PHP:
-
<?php
-
...
-
//return $this->cakeError(...);
-
$this->cakeError(...); // returnしない
-
...
-
?>
Object#cakeError()
PHP:
-
function cakeError($method, $messages) {
-
...
-
$error = new AppError($method, $messages);
-
} else {
-
$error = new ErrorHandler($method, $messages);
-
}
-
-
exit;
-
}
- Newer: 日付時間はDateTimeクラスで
- Older: CakePHP1.1.10.3825リリース
トラックバック:0
- このエントリーのトラックバックURL
- http://www.1x1.jp/blog/2006/11/cakephp_cake_error.html/trackback
- Listed below are links to weblogs that reference
- CakePHP cakeError()は値を返さない from Shin x blog

