【问题标题】:How to set up ErrorHadler via application.ini?如何通过 application.ini 设置 ErrorHadler?
【发布时间】:2010-12-12 14:48:12
【问题描述】:

我以这种方式在Bootstrap.php 中设置默认errorHandler

public function _initErrorHandler()
{
    $frontController = Zend_Controller_Front::getInstance();
    $plugin = new Zend_Controller_Plugin_ErrorHandler(
        array(
            'module' => 'default',
            'controller' => 'error',
            'action' => 'error'
    ));
    $frontController->registerPlugin($plugin);

    return $plugin;
}

我怎样才能通过application.ini 选项做同样的事情?

【问题讨论】:

  • 错误处理器不是默认激活的吗?
  • @ArneRie 是的。但是在默认模块中。当我将其他模块设置为默认模块时,我需要一种简单的方法来更改它。

标签: zend-framework configuration config zend-application


【解决方案1】:

如果您的意思是“自动”,我认为这是不可能的,因为 ErrorHandler 插件不是资源插件。

但是,如果您想引导自己的个人错误处理程序,您可以执行以下操作:

在您的 application.ini 中:

errorhandler.class = "Zend_Controller_Plugin_ErrorHandler"
errorhandler.options.module = default
errorhandler.options.controller = error
errorhandler.options.action = error 

并且,在您的引导程序中加载这些选项:

public function _initErrorHandler()
{
    // make sure the frontcontroller has been setup
    $this->bootstrap('frontcontroller');
    $frontController = $this->getResource('frontcontroller');
    // option from the config file
    $pluginOptions   = $this->getOption('errorhandler');
    $className       = $pluginOptions['class'];

    // I'm using zend_loader::loadClass() so it will throw exception if the class is invalid.
    try {
        Zend_Loader::loadClass($className);
        $plugin          = new $className($pluginOptions['options']);
        $frontController->registerPlugin($plugin);
        return $plugin;
    } catch (Exception $e) {
        // do something useful here (like fall back to the default error handler)
        echo $e->getMessage();
        return null;
    }
}

【讨论】:

  • 谢谢。这是我已经做过的事情,但我正在寻找跳过 Bootstrap 代码的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
  • 2011-07-03
相关资源
最近更新 更多