我目前正在开发一个基于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);
}
// ...
我应该在哪里以及如何处理这个问题?
您可以检查是否抛出Zend_Db_Exception:
if($errors->exception and $errors->exception instanceof Zend_Db_Exception) {
// do something
}