Advertisement
mogaj

errors controller

Feb 18th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. Using zf1.12
  2. --------------------------------------------------------------------------------------------
  3.  
  4. App_ErrorController
  5. -------------------------
  6. class App_ErrorController extends Zend_Controller_Action
  7. {
  8.  
  9.     public function errorAction()
  10.     {
  11.         $this->view->Paths = $this->view->getHelper('Paths');
  12.  
  13.         $errors = $this->_getParam('error_handler');
  14.        
  15.         if (!$errors || !$errors instanceof ArrayObject) {
  16.             $this->view->message = 'You have reached the error page';
  17.             return;
  18.         }
  19.        
  20.         switch ($errors->type) {
  21.             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
  22.             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
  23.             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
  24.                 // 404 error -- controller or action not found
  25.                 $this->getResponse()->setHttpResponseCode(404);
  26.                 $priority = Zend_Log::NOTICE;
  27.                 $this->view->message = 'Page not found';
  28.                 break;
  29.             default:
  30.                 // application error
  31.                 $this->getResponse()->setHttpResponseCode(500);
  32.                 $priority = Zend_Log::CRIT;
  33.                 $this->view->message = 'Application error';
  34.                 break;
  35.         }
  36.        
  37.         // Log exception, if logger available
  38.         if ($log = $this->getLog()) {
  39.             $log->log($this->view->message, $priority, $errors->exception);
  40.             $log->log('Request Parameters', $priority, $errors->request->getParams());
  41.         }
  42.        
  43.         // conditionally display exceptions
  44.         if ($this->getInvokeArg('displayExceptions') == true) {
  45.             $this->view->exception = $errors->exception;
  46.         }
  47.        
  48.         $this->view->request   = $errors->request;
  49.     }
  50.  
  51.     public function getLog()
  52.     {
  53.         $bootstrap = $this->getInvokeArg('bootstrap');
  54.         if (!$bootstrap->hasResource('Log')) {
  55.             return false;
  56.         }
  57.         $log = $bootstrap->getResource('Log');
  58.         return $log;
  59.     }
  60.  
  61.  
  62. }
  63.  
  64. --------------------------------------------------------------------------------------------------
  65. Errors view file
  66. ------------------------------------------
  67. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  68. <html xmlns="http://www.w3.org/1999/xhtml">
  69. <head>
  70.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  71.   <title>Zend Framework Default Application</title>
  72. </head>
  73. <body>
  74.   <h1>An error occurred</h1>
  75.   <h2><?php echo $this->message ?></h2>
  76.  
  77.   <?php if (isset($this->exception)): ?>
  78.  
  79.   <h3>Exception information:</h3>
  80.   <p>
  81.       <b>Message:</b> <?php echo $this->exception->getMessage() ?>
  82.   </p>
  83.  
  84.   <h3>Stack trace:</h3>
  85.   <pre><?php echo $this->exception->getTraceAsString() ?>
  86.   </pre>
  87.  
  88.   <h3>Request Parameters:</h3>
  89.   <pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?>
  90.   </pre>
  91.  
  92.   <?php endif ?>
  93.  
  94. </body>
  95. </html>
  96. ---------------------------------------------------------------------------------------------------
  97. application.ini file
  98. ----------------------------------------------
  99. [production]
  100. phpSettings.display_startup_errors                          = 1
  101. phpSettings.display_errors                                  = 1
  102. includePaths.library                                        = APPLICATION_PATH "/../library"
  103. autoloaderNamespaces[]                                      = "Nirvana_"
  104. bootstrap.path                                              = APPLICATION_PATH "/Bootstrap.php"
  105. bootstrap.class                                             = "Bootstrap"
  106. appnamespace                                                = "Application"
  107. ;resources.frontController.controllerDirectory              = APPLICATION_PATH "/controllers"
  108. resources.frontController.params.displayExceptions          = 1
  109.  
  110. ; 2012-08-30
  111. resources.frontController.baseUrl                           = ""
  112.  
  113. resources.layout.layoutPath                                 = APPLICATION_PATH "/layouts/scripts/"
  114.  
  115. ; 2012-08-30 - for layouts/views
  116. resources.view[]                                            =
  117. ; 2012-08-31 - for view helpers
  118. resources.view.helperPath                                   = APPLICATION_PATH "/views/helpers"
  119.  
  120. ; 2012-08-30 - for sessions
  121. resources.session.use_only_cookies = true
  122. resources.session.cookie_httponly = true
  123. resources.session.name = 'nirvana'
  124. resources.session.cookie_secure = false
  125. resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
  126. resources.modules[] =
  127. resources.frontController.params.prefixDefaultModule = "1"
  128. resources.frontController.defaultModule = "Application"
  129. [staging : production]
  130.  
  131. [testing : production]
  132. phpSettings.display_startup_errors = 1
  133. phpSettings.display_errors = 1
  134.  
  135. [development : production]
  136. phpSettings.display_startup_errors = 1
  137. phpSettings.display_errors = 1
  138. resources.frontController.params.displayExceptions = 1
  139.  
  140. resources.db.adapter = "PDO_PGSQL"
  141. resources.db.params.host = "localhost"
  142. resources.db.params.dbname = "test_nirvana"
  143. resources.db.params.username = "postgres"
  144. resources.db.params.password = "postgres"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement