yaf将错误输出打印在页面上

修改项目的配置文件

文件是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 YafController_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> 

这个时候如果直接在浏览器上,输入一个不存在的网址时,程序会把错误输入到页面上.

原文地址:https://www.cnblogs.com/wangkongming/p/5117686.html