Hi,
I am wondering why my error template is not rendered when an exception
is thrown in my authorization plugin.
Let me explain the context.
1) my bootstrap registers a plugin for authorization:
...
$frontController = Zend_Controller_Front::getInstance();
$frontController->setControllerDirectory(WEBAPP_CONTROLLER_DIR);
$view = new Zend_View($config->view->toArray());
$viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view)
->setViewBasePathSpec(WEBAPP_VIEW_DIR);
$auth = Zend_Auth::getInstance();
$acl = new Permission();
$frontController->registerPlugin(new
Technema_Plugin_Authorization($auth, $acl));
2) my plugin throws an exception when user is not allowed to
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($this->_auth->hasIdentity()) {
$role = $this->_auth->getIdentity()->role;
} else {
$role = $this->_config->acl->guest;
}
$module = $request->module;
$controller = $request->controller;
$action = $request->action;
$resource = $controller;
if (!$this->_acl->has($resource)) {
$resource = null;
}
if (!$this->_acl->isAllowed($role, $resource, $action)) {
if ($this->_auth->hasIdentity()) {
throw new Zend_Acl_Exception($resource . '/' . $action);
...
3) by default, the front controller registers an error handler that
triggers the ErrorController
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
$this->getResponse()->clearBody();
$error = $this->_getParam('error_handler');
switch ($error->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';
break;
default:
switch (get_class($error->exception)) {
case 'Zend_Acl_Exception' :
$this->getResponse()->setHttpResponseCode(200);
$this->view->message = 'Access denied to page '
. $error->exception->getMessage();
Zend_Registry::get(REG_LOG)->debug('Access
denied to ' . $error->exception->getMessage());
break;
...
When I try to access a resource I am not allowed to, I am sure the
ErrorController is triggered because I find an "Access denied..." in my
log. But I get a plain text error message instead of my custom error
page (views/scripts/error/error.phtml)
Where am I wrong?
--
View this message in context:
http://www.nabble.com/error-template-not-rendered-when-exception-is-raised-tp19458736p19458736.html
Sent from the Zend Framework mailing list archive at Nabble.com.