Reputation: 1027
I am new to zendframework. Now i am facing problem with error reporting; when i makes small mistakes it's show me a long error message like this
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /var/www/html/workbench/zend/library/Zend/Controller/Dispatcher/Standard.php:248 Stack trace: #0 /var/www/html/workbench/lajeesh/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /var/www/html/workbench/lajeesh/zend/library/Zend/Controller/Front.php(212): Zend_Controller_Front->dispatch() #2 /var/www/html/workbench/sudeepc/zend/web_root/index.php(10): Zend_Controller_Front::run('../application/...') #3 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)#0 /var/www/html/workbench/lajeesh/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /var/www/html/workbench/lajeesh/zend/library/Zend/Controller/Front.ph in /var/www/html/workbench/lajeesh/zend/library/Zend/Controller/Plugin/Broker.php on line 336
and so on.... . so my question is how can i configure zend framework error reporting more user friendly ?
Upvotes: 2
Views: 549
Reputation: 11
what i have done : edit in library/Zend/Controller/Dispatcher/Standard.php
find where there are :
try {
$controller->dispatch($action);
} catch (Exception $e) {
// Clean output buffer on error
$curObLevel = ob_get_level();
if ($curObLevel > $obLevel) {
do {
ob_get_clean();
$curObLevel = ob_get_level();
} while ($curObLevel > $obLevel);
}
throw $e;
}
it is just after :
/**
* Dispatch the method call
*/
and add die($e->getMessage()); in the catch block : you will get :
try {
$controller->dispatch($action);
} catch (Exception $e) {
die($e->getMessage());
// Clean output buffer on error
$curObLevel = ob_get_level();
if ($curObLevel > $obLevel) {
do {
ob_get_clean();
$curObLevel = ob_get_level();
} while ($curObLevel > $obLevel);
}
throw $e;
}
then the message delivered by Zend will be more explicit.
Upvotes: 1
Reputation: 7954
Error management is done in the following files..you can customize the way you want 1.ErrorController 2.error/error.phtml
ErrorController.php
<?php
class ErrorController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->layout->setLayout('set your default layout here'); //so it will be much more nicer
}
public function errorAction()
{
$errors = $this->_getParam('error_handler');
if (!$errors) {
$this->view->message = 'You have reached the error page';
return;
}
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
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 = PackAssist_Locale::translate('Sorry, the page doesnt exists'); //This is a custom message
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error'; // put any custom messages if you want
break;
}
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->crit($this->view->message, $errors->exception);
}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
public function getLog()
{
$bootstrap = $this->getInvokeArg('bootstrap');
if (!$bootstrap->hasResource('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
}
}
error.phtml
<div>
<h1><?php echo $this->translate('An error occurred');?></h1>
<h2><?php echo $this->message; //Base error message ?></h2>
<?php if (isset($this->exception)): ?>
<h3><?php echo $this->translate('Exception information');?>:</h3>
<p>
<b>Message:</b> <?php echo $this->exception->getMessage(); ?>
</p>
<h3>Stack trace:</h3>
<pre><?php echo $this->exception->getTraceAsString(); //You can hide this for the end user ?>
</pre>
<h3>Request Parameters:</h3>
<pre><?php echo var_export($this->request->getParams(), true); // This will bea an array of your requested params POST/GET variables,your controller and the current action that produced the error ?>
</pre>
3.If you want to completely hide the errors.just put these lines in your config file
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
Upvotes: 3