Zend Framework a useful error class
Am pornit de la clasa asta, si am "curatato un pic" dupa bunul meu plac si deasemenea am folosit Zend_Log nu Zend_Mail, ca nu am chef sa primesc 5000 precum ca niste idiotii nu au nimerit un url corect si etc, mai bine frumos totul scris!
ErrorController.php
<?php
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
// Ensure the default view suffix is used so we always return good
// content
$this->_helper->viewRenderer->setViewSuffi'phtml');
// Grab the error object from the request
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
$this->view->code = 404;
if ($errors->type == Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER) {
$this->view->info = sprintf(
'Unable to find controller "%s" in module "%s"',
$errors->request->getControllerName(),
$errors->request->getModuleName()
);
}
if ($errors->type == Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION) {
$this->view->info = sprintf(
'Unable to find action "%s" in controller "%s" in module "%s"',
$errors->request->getActionName(),
$errors->request->getControllerName(),
$errors->request->getModuleName()
);
}
break;
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
$this->view->code = 500;
$this->view->info = $errors->exception;
break;
}
/*-------------------------------------------
--START-- Logg the errors using Zend_Log
--------------------------------------------*/
$writer = new Zend_Log_Writer_Stream(Zend_Registry::get('root').'/logs/logs.ini');
$logger = new Zend_Log($writer);
$toLog = $this->view->message." (".$this->view->code.")nn";
$toLog .= "Zend Error Type: ".$errors->type."nn";
$toLog .= "REQUEST_URI: ".$_SERVER['REQUEST_URI']."nn";
if ( isset($_SERVER['HTTP_REFERER']) ) {
$toLog .= "HTTP_REFERER: ".$_SERVER['HTTP_REFERER']."nn";
}
$toLog .= "Stack trace: nn". $errors->exception->getTraceAsString()."nn";
$logger->log($toLog, Zend_Log::INFO);
/*-------------------------------------------
--END-- Logg the errors using Zend_Log
--------------------------------------------*/
$this->view->title = 'Error!';
$this->view->heading = 'Oups! Error!';
// pass the environment to the view script so we can conditionally
// display more/less information
$this->view->env = $this->getInvokeArg('env');
// pass the actual exception object to the view
$this->view->exception = $errors->exception;
// pass the request to the view
$this->view->request = $errors->request;
}
}
error.phtml
<p>
<h3><?=$this->message ?> (<?=$this->code ?></h3>
</p>
<?php
if( $this->env == 'test' ):
if ( isset($this->info ) ): ?>
<? if ( 404 == $this->code ): ?>
<p><b>Reason:</b> <?= $this->info ?></p>
<?php elseif (500 == $this->code): ?>
<p>Bad server, naughty server!<br />No donut for you!</p>
<h4>Exception information:</h4>
<p><b>Message:</b> <?= $this->info->getMessage() ?></p>
<h4>Stack trace:</h4>
<pre><?= $this->info->getTraceAsString() ?></pre>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
'phtml');
</h3>
age, well astazi am avut nevoie de ceva diferit, din moment ce am mai avut m-ai multe pagina-ri pe o pagina.
