2

errorHandler私はこのようにデフォルトを設定しましたBootstrap.php

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オプションで同じようにするにはどうすればよいですか?

4

1 に答える 1

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;
    }
}
于 2010-12-12T18:22:26.207 に答える