2010-12-12 1 views
2

настроить по умолчанию errorHandler в Bootstrap.php так:Как установить ErrorHadler через application.ini?

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

Если вы имеете в виду «автоматически», я не думаю, что это возможно, так как плагин 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; 
    } 
} 
+0

Спасибо. Это то, что я уже делаю, но я искал способ пропустить код в Bootstrap. – takeshin

 Смежные вопросы

  • Нет связанных вопросов^_^