Yaf throws are divided into error and exception levels. Here I stenographer how to customize the exception capture that has been handled
The system throws by default usually expose your file structure and naming method. When the system is facing the public network, it is necessary for us to block or handle this.
define("APP_PATH", __DIR__);$app = new Yaf_Application(APP_PATH . "/conf/application.ini");$app->getDispatcher()->catchException(true);$app->bootstrap()->run();
This setting is also acceptable. I am not very clear about which efficiency is better. Please tell me if you know more about the boots.
Yaf_Dispatcher::getInstance()->catchException(true);
Set catchexception to true, which can be customized
Simple capture Processing
Create an error Controller under the current module and create an erroraction
class ErrorController extends Yaf_Controller_Abstract { public function errorAction($exception) { Yaf_Dispatcher::getInstance()->disableView(); /* error occurs */ switch ($exception->getCode()) { case YAF_ERR_NOTFOUND_MODULE: case YAF_ERR_NOTFOUND_CONTROLLER: case YAF_ERR_NOTFOUND_ACTION: case YAF_ERR_NOTFOUND_VIEW: echo 404, ":", $exception->getMessage(); break; default : $message = $exception->getMessage(); echo 0, ":", $exception->getMessage(); break; } }}
Function setting is also relatively simple, and throws are converted from exceptions to error levels.
$app->getDispatcher()->throwException(FALSE);$app->getDispatcher()->setErrorHandler("myErrorHandler");$app->bootstrap()->run();function myErrorHandler($errno, $errstr, $errfile, $errline){ switch ($errno) { case YAF_ERR_NOTFOUND_CONTROLLER: case YAF_ERR_NOTFOUND_MODULE: case YAF_ERR_NOTFOUND_ACTION: header("Not Found"); break; default: echo 'errno: '.$errno.'<br>'; echo 'errstr: '.str_replace(APP_PATH, '[PATH]', $errstr).'<br>'; echo 'errfile: '.str_replace(APP_PATH, '[PATH]', $errfile).'<br>'; echo 'errline: '.$errline.'<br>'; break; } return true;}
How does yaf customize to throw an exception catchexception?