一般在yaf项目调试的时候,如果代码有错误,页面只会响应500错误,但看不到哪里报了什么错误,通过开启yaf的一个配置可以将错误信息显示在页面上。
打开项目的index.php入口文件,在开头加入如下代码:
ini_set(\'display_errors\', 1); error_reporting(E_ALL);
比如我的index.php入口文件内容如下:
<?php ini_set(\'display_errors\', 1); error_reporting(E_ALL); define("APP_ROOT", realpath(dirname(__FILE__).\'/..\')); define("APP_ENV", getenv(\'APP_ENV\') ? getenv(\'APP_ENV\') : \'product\'); define("DATA_PATH", APP_ROOT.\'/data\'); set_include_path(implode(PATH_SEPARATOR, array( realpath(APP_ROOT . \'/vendor\'), get_include_path(), ))); $app = new Yaf_Application(APP_ROOT . "/conf/application.ini"); $app->bootstrap()->run();
我故意配置一个错误的数据库信息,在页面也会打印出错误信息:
如果没有开启上面的配置,页面将会展示500错误,而看不到具体的错误信息: