ActionController 例外をキャプチャするために「set_exception_handler」関数を使用してみます。
index.phtml などの任意のビュー内では、このコードは正常に機能し、ビューには Helloooo が表示されます。
<?php
namespace App;
echo $this->doctype();
class Fun {
static function exception_handler(\Exception $ex){
echo "Heloooo";
}
function method(){
set_exception_handler('App\Fun::exception_handler');
throw new \Exception('One Exception');
}
}
$f = new Fun();
$f->method();
ActionController.php 内の同じコード、set_exception_handler() が例外をキャッチしないため、わかりません。この場合、ビューには「One Exception」メッセージを含む zend 例外テンプレートが表示されます。
ちなみに、例外スタックに警告メッセージが表示されない場合は、 set_exception_handler() パラメータが正常であると想定しています。
namespace App\Controller;
use Zend\....... //All namespaces used
class Fun {
static function exception_handler(\Exception $ex){
echo "Helloooo";
}
function method(){
set_exception_handler('App\Controller\Fun::exception_handler');
throw new \Exception('One Exception');
}
}
$f = new Fun();
$f->method();
class MainController extends AbstractActionController {
//The Controller Code (in this test it doesn't execute).
}
Zend Framework は、他のレベルでコントローラーの例外をキャッチするためにあらゆる手法を使用していると思います。誰かがそれを行うためのアイデアを持っていますか?