修改项目的配置文件
文件是conf/application.ini
添加两行代码
application.dispatcher.throwException = 1
;开启/关闭自动异常捕获功能
application.dispatcher.catchException = 1
新建Error.php文件
文件目录是application/controllers/Error.php
<?php
/**
* ErrorController-
*-
* @uses Yaf
* @uses _Controller_Abstract
* @package-
* @version $Id$
* @author wangkongming <komiles@163.com>
*/
class ErrorController extends Yaf\Controller_Abstract {
public function errorAction($exception) {
$message = $exception->__toString();
$this->getView()->assign("code", $exception->getCode());
//$this->getView()->assign("message", $exception->getMessage());
$this->getView()->assign("message", $message);
$this->getView()->display('error/error.html');
exit;
}
}
新建对应的模板文件
文件目录是application/views/error/error.html
<html>
<head>
<title>Error</title>
</head>
<body>
<?php echo $code;?>
<br />
<?php echo $message;?>
</body>
</html>