【问题标题】:Error reporting in zend frameworkZend 框架中的错误报告
【发布时间】:2011-07-20 13:35:12
【问题描述】:

在 zend 框架中报告错误时遇到问题,错误消息未显示在浏览器上,我收到如下错误:

发生错误

应用程序错误

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

phpSettings.display_startup_errors = 1

phpSettings.display_errors = 1

phpSettings.track_errors = 1

phpSettings.error_reporting = E_ALL

提前致谢:D

【问题讨论】:

  • 你能给我们看看你的errorController中的一些代码吗?

标签: php zend-framework error-reporting


【解决方案1】:

我遇到了同样的问题,最终分两步解决:

1.打开{project name}/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.修改{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();

?>

希望这对你也有用。

【讨论】:

    【解决方案2】:

    您提到的设置是 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 语句阻塞了生产环境
    猜你喜欢
    • 2013-03-03
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    相关资源
    最近更新 更多