|
|||
|
Hi there
need a quick help about Zend_Controller_Plugin_ErrorHandlerI use it with my As_Controller_Plugin_Auth which works in preDispatch() method. The last one uses ACL object to consider redirection to auth controller. And now if: Code:
!$this->_acl->isAllowed($role, $resource, $action) Code:
if (!$this->_acl->has($resource)) {
$resource = null;
}
Earlier I used my own NoRoute plugin which used preDispatch() instead of postDispatch() and it was checking controller's dispatchable before As_Controller_Plugin_Auth was run. Therefore I suppose that I need a preDispatch check if there is no route. Can I do this with Zend_Controller_Plugin_ErrorHandler? Maybe someone just wrote class override Zend_Controller_Plugin_ErrorHandler with preDispatch() method? here is As_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract class: Code:
<?php
class As_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
private $_auth;
private $_acl;
private $_noauth = array('module' => 'default', 'controller' => 'auth', 'action' => 'login');
private $_noacl = array('module' => 'default', 'controller' => 'error', 'action' => 'privileges');
public function __construct($auth, $acl)
{
$this->_auth = $auth;
$this->_acl = $acl;
}
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($this->_auth->hasIdentity()) {
$role = $this->_auth->getIdentity()->role;
} else {
$role = 'guest';
}
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
$resource = $module . '_' . $controller;
if (!$this->_acl->has($resource)) {
$resource = null;
}
if (!$this->_acl->isAllowed($role, $resource, $action)) {
if (!$this->_auth->hasIdentity()) {
$module = $this->_noauth['module'];
$controller = $this->_noauth['controller'];
$action = $this->_noauth['action'];
} else {
$module = $this->_noacl['module'];
$controller = $this->_noacl['controller'];
$action = $this->_noacl['action'];
}
}
$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);
}
}
Last edited by sk0rp : 07-25-2007 at 05:23 PM. |
|
|||
|
Finaly I wrote my As_Controller_Plugin_ErrorHandler class. I welcome any sugestions to the code below
![]() EDIT: I add some changes and now plugin works ok with module controllers PHP Code:
Last edited by sk0rp : 07-28-2007 at 07:53 AM. |
|
|||
|
Thanks a lot. I was searching all over for someone else who had this same problem. So far the code works very smoothly.
![]() |
![]() |
| Thread Tools | |
| Display Modes | |
|
|