isAllowed() is not taking the parameters value
class Application_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract
{
private $_auth=null;
private $_acl=null;
public function __construct() {
$auth = Zend_Auth::getInstance();
$acl = new Zend_Acl;
$this->_auth = $auth;
$this->_acl = $acl;
}
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$resource = $request->getControllerName();
$action = $request->getActionName();
$identity = $this->_auth->getStorage()->read();
$role = $identity->role;
if(!$this->_acl->isAllowed($role,$resource,$action)){
$request->setControllerName('Auth')
->setActionName('login');
}
//echo '<pre>';print_r('inside plugins......success');die();
}
}
This is the ACL plugin page i am using.
In this particular line
if(!$this->_acl->isAllowed($role,$resource,$action))
The function isAllowed is not taking the parameters, the url comes blank.
If i assign if(!$this->_acl->isAllowed($role=null,$resource=null,$action=null)), the page opens but it doesn't have any meaning if i set null.
Seeking for Help
I am adding the model class "AsiaAcl.php" for more clearification
class Model_Asian_Acl extends Zend_Acl{
public function __construct(){
$this->add(new Zend_Acl_Resource('data'));
$this->add(new Zend_Acl_Resource('updatecat'),'data');
$this->add(new Zend_Acl_Resource('detelecategory'),'data');
$this->add(new Zend_Acl_Resource('datas'));
$this->add(new Zend_Acl_Resource('listcat'),'datas');
$this->addRole(new Zend_Acl_Role('user'));
$this->addRole(new Zend_Acl_Role('admin'),'user');
$this->allow('user','dat开发者_开发问答as','listcat');
$this->allow('admin','data','updatecat');
$this->allow('admin','data','deletecategory');
}
}
Thanks.
I hope I am not blind but your ACL is just an empty object. From what I see you have not assigned any roles and access control to the ACL.
With isAllowed() you check a role and resource but there is nothing the ACL has to check against. You have to either create/extend your own ACL class or you assign the roles and controls on the fly in your plugin.
See ACL Doku
Update
Great, you have your own ACL class but you are not using it!
$acl = new Zend_Acl;
// this is just the empty default ACL, no roles nothing
// you should connect your own ACL class like this
$acl = new Model_Asian_Acl;
If haven't look at your ACL class closely but I think it should work.
精彩评论