2010-12-12 4 views
2

私はBootstrap.phpにこの方法をデフォルトerrorHandlerを設定します。application.iniからErrorHadlerを設定するには?

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オプションを経由して同じことをすることができますか?

+1

デフォルトではエラーハンドラはアクティブではありませんか? – opHASnoNAME

+0

@ArneRieはい、そうです。しかし、デフォルトモジュールでは。他のモジュールをデフォルトのものに設定すると、簡単に変更する必要があります。 – takeshin

+0

見てください:https://github.com/codeinchaos/restful-zend-framework#module-specific-errorcontroller-issue – falko

答えて

1

「自動」とは、エラーハンドラプラグインがリソースプラグインではないため、可能ではないと思います。あなたの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; 
    } 
} 
+0

ありがとうございます。これは私がすでにやっていることですが、私はBootstrapのコードをスキップする方法を探していました。 – takeshin

関連する問題