我目前正在开发一个基于Zend 1.11的项目,我需要捕获与数据库相关的异常,并在发生通知时显示通知。毋庸置疑,我对Zend Framework完全陌生......
根据我在ErrorController中定义的默认操作中看到的内容,我不知道如何实现这一点:
class ErrorController extends Zend_Controller_Action
{
private $logPriority_;
public function errorAction()
{
$errors = $this->_getParam('error_handler');
if (!$errors || !$errors instanceof ArrayObject)
$this->_forward('notfound','error');
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->_forward('notfound','error');
break;
default:
// application error
break;
}
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = '500 Internal Server Error';
$this->logErrors(Zend_Log::CRIT);
}
// ...
我应该在何处以及如何处理此问题?
答案 0 :(得分:2)
您可以检查是否抛出了Zend_Db_Exception:
if($errors->exception and $errors->exception instanceof Zend_Db_Exception) {
// do something
}