Zend框架中的错误报告

11

我在使用Zend框架时遇到了报错问题,但是错误信息没有显示在浏览器上,我收到的错误信息如下:

发生了一个错误

应用程序错误

尽管我已经在我的application.ini文件中使用了这些配置:

phpSettings.display_startup_errors = 1

phpSettings.display_errors = 1

phpSettings.track_errors = 1

phpSettings.error_reporting = E_ALL

提前感谢 :D


1
你能展示一下你的errorController的代码吗? - KJYe.Name
2个回答

13
您提到的设置是PHP错误管理,而您正在寻找的实际上是Zend错误和异常报告。就像kjy112所说,看起来Zend默认为生产环境,不显示任何错误报告。
Zend快速入门可能是帮助您快速了解此内容的最快方法: http://framework.zend.com/manual/en/zend.application.quick-start.html 基本上,您可以在index.php文件中设置一个定义(不是最干净的方式),或者我建议在您的Apache配置中设置它,然后从index.php文件中读取它。我在我的引导程序中使用类似于以下内容:
if (!defined('APPLICATION_ENVIRONMENT'))
{
    if (getenv('APPLICATION_ENVIRONMENT')) {
        define('APPLICATION_ENVIRONMENT', getenv('APPLICATION_ENVIRONMENT'));
    } else {
        define('APPLICATION_ENVIRONMENT', 'production');
    }
}

默认的Zend error.phtml视图具有类似于以下代码的内容,该代码会阻止在生产环境中显示:

<?php if ('production' !== $this->env): ?>
<div id="error">
    <p>
        <ul class="errorList">
            <li>
                <h3><?php echo $this->message ?></h3> 
            </li>
            <li>
                <h4>Exception information:</h4>
                <p><?php echo $this->exception->getMessage() ?></p>
            </li>
            <li>
                <h4>Stack trace:</h4>
                <p><?php echo $this->exception->getTraceAsString() ?></p>
            </li>
            <li>
                <h4>Request Parameters:</h4>
                <p><?php var_dump($this->request->getParams()) ?></p>
            </li>
        </ul>
    </p>
</div>
<?php endif ?>

是的,有一个if语句阻止了生产环境。 - Ahmad A Bazadgha

3

我曾经遇到过同样的问题,最终通过以下两个步骤解决:

1.打开{项目名称}/application/configs/application.ini文件,在末尾添加以下行:

[development : production]  
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
settings.debug.enabled = 1

2.Modify {project name}/public/index.php

<?php    
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Typically, you will also want to add your library/ directory
// to the include_path, particularly if it contains your ZF installed
set_include_path(implode(PATH_SEPARATOR, array(
    dirname(dirname(__FILE__)) . '/library',
    get_include_path()
)));

/**
 * Zend_Application
 */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();

?>

希望这对您也有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接