Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/06/2012, 01:54
Avatar de malconsoft
malconsoft
 
Fecha de Ingreso: septiembre-2011
Ubicación: Lima, Peru
Mensajes: 3
Antigüedad: 12 años, 8 meses
Puntos: 0
personalizar errores

Hola a todos,
tengo un dilema , creo que puede ser por falta de entendimiento de los conceptos creo yop.

quiero que se muestren todos mis errores pero veo que NO me captura los errores que se
producen en el Bootstrap.php

¿Como haria para capturar hasta los error FATAL ERROR o errores de PHP ?
Errores de sintaxis, clase que no exista, etc
gracias

EJEMPLO:

He forzado el error, colocando una ruta de directorio erronea la ubicacion del log en el
application.ini
Código PHP:
Ver original
  1. //application/configs/application.ini
  2. ;-------------------------------
  3. ; LOG DE ERRORES
  4. ;-------------------------------
  5. log.path = APPLICATION_PATH "/../logxxxx/application.log"
  6. log.stream.mode = "a"

Código PHP:
Ver original
  1. //application/modules/default/controllers/ErrorController.php
  2.  
  3. <?php
  4. /**
  5.  * Description of ErrorController
  6.  *
  7.  * @author MALCON
  8.  */
  9. class Default_ErrorController extends Zend_Controller_Action
  10. {
  11.     private $_logger;
  12.     private $_config;
  13.  
  14.     public function init()
  15.     {
  16.         $this->_config = Zend_Registry::get('config');
  17.         $this->_logger = Zend_Registry::get('logger');
  18.     }
  19.    
  20.     public function errorAction()
  21.     {
  22.         $errors = $this->_getParam('error_handler');
  23.         $modulename = $errors->request->getModuleName();
  24.         $this->view->modulename = $modulename;
  25.         $this->view->controllername = $errors->request->getControllerName();
  26.         $this->view->actionname = $errors->request->getActionName();
  27.         $this->view->mensaje= '';
  28.         $this->view->env = APPLICATION_ENV;
  29.         //cambiar layout de error si el modulo es diferente al
  30.         //backoffice
  31.         if ($modulename != 'backoffice') {
  32.             $this->initView();
  33.             Zend_Layout::getMvcInstance()->setLayout('error');
  34.         }
  35.         switch ($errors->type) {
  36.         //Error MVC
  37.             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
  38.             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
  39.                 //devolveremos un código 404 de página inexistente
  40.                 $this->getResponse()->setHttpResponseCode(404);
  41.                 $this->_forward('notfound');
  42.                 break;
  43.             //No es un error MVC
  44.             default:
  45.             //se cogenlas excepciones que han saltado
  46.             $errores = $this->getResponse()->getException();
  47.             //se trata cada tipo de excepcion
  48.             foreach ($errores as $error) {
  49.                 switch(get_class($error)) {
  50.                     case 'Zend_Db_Statement_Exception':
  51.                         $this->view->mensaje = 'ERROR DE BBDD: ' . $error->getMessage();
  52.                         break;
  53.                     case 'Zend_View_Exception':
  54.                         $this->view->mensaje = 'ERROR EN LA VISTA: ' . $error->getMessage();
  55.                         break;
  56.                     case 'Zend_Loader_Exception':
  57.                         $this->view->mensaje = 'ERROR AL CARGAR: ' . $error->getMessage();
  58.                         break;
  59.                     case 'Zend_Form_Exception':
  60.                         $this->view->mensaje = 'ERROR EN EL FORMULARIO: ' . $error->getMessage();
  61.                         break;
  62.                     //cualquier error no especifico
  63.                     default:
  64.                         $this->view->mensaje= 'Error desconocido!';
  65.                         break;
  66.                 } //end switch(get_class($error))
  67.             }
  68.             break; //terminar con los errores no MVC
  69.         }
  70.  
  71.         if ($this->getInvokeArg('displayExceptions') == true) {
  72.             $this->view->exception = $errors->exception;
  73.         }
  74.         $this->view->request   = $errors->request;
  75.  
  76.         //mensaje de email del error        
  77.         if (APPLICATION_ENV == 'production') {
  78.             $body = $this->view->mensaje . "\n"
  79.                 . '<pre>' . $errors->exception->getTraceAsString()
  80.                 . '</pre>';
  81.             $this->_logger->crit($body); //guardar log de error
  82.             $this->enviarcorreo($body); // enviar por correo error
  83.         }
  84.         return;
  85.     }
  86.  
  87.     public function enviarcorreo($body)
  88.     {
  89.         try {
  90.             $mail = new Zend_Mail();
  91.             $mail->setFrom($this->_config->mail->de, 'Soporte');
  92.             $mail->addTo($this->_config->mail->para, 'Receptor');
  93.             $mail->setSubject($this->_config->mail->asunto);
  94.             $mail->setBodyHtml($body);
  95.             $mail->send();
  96.             $this->_logger->info('mail enviado exitosamente a '
  97.                 . $this->_config->mail->para);
  98.         } catch (Zend_Mail_Exception $e) {
  99.             $this->_logger->crit('Problemas al enviar email a '
  100.                     . $this->_config->mail->para .'<br/>'
  101.                     . 'Mensaje : ' . $e->getMessage());
  102.             throw $e;
  103.         }
  104.     }
  105. }

Última edición por malconsoft; 09/06/2012 a las 22:55