2010-12-12 6 views
2

stelle ich errorHandler in Bootstrap.php auf diese Weise Vorgegeben:Wie ErrorHadler über application.ini einrichten?

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; 
} 

Wie kann ich das gleiche über application.ini Optionen?

+1

Ist der Fehlerhandler standardmäßig nicht aktiv? – opHASnoNAME

+0

@ArneRie Ja, ist es. Aber im Standardmodul. Ich brauche eine einfache Möglichkeit, es zu ändern, wenn ich ein anderes Modul als Standard setze. – takeshin

+0

Schauen Sie sich an: https://github.com/codeinchaos/restful-zend-framework#module-specific-errorcontroller-issue – falko

Antwort

1

Wenn Sie "automatisch" meinen, glaube ich nicht, dass es möglich ist, da das ErrorHandler-Plugin kein Ressourcen-Plugin ist.

Aber, wenn Sie Ihre eigene persönliche Fehler-Handler Bootstrap möchten, können Sie etwas tun können:

in application.ini:

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

Und in der Bootstrap diese Optionen zu laden :

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

Danke. Das mache ich schon, aber ich habe den Weg gesucht, den Code in Bootstrap zu überspringen. – takeshin

Verwandte Themen