CakePHP & PHP 2006/11/08 18:37
CakePHP cakeError()は値を返さない
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;
-
}
■Related Posts




