我正在网站上工作,在CV部分用户有一些只登录用户可以下载的文章。我想更改登录操作或preDispatch()以设置访客用户下载文章的会话。
有人可以告诉我如何做或给我一些参考链接吗?
这是我的preDispatch():
public function preDispatch()
{
$userInfo=$this->_auth->getStorage()->read();
$identity= $this->_auth->getIdentity();
if(!$this->_auth->hasIdentity())
{
return $this->_helper->redirector('login','login');
}
if(!isset($userInfo["member_id"]) || strlen($userInfo["member_id"])==0)
{
return $this->_helper->redirector('forbidden','login');
}
$this->_accessType=2;
}
答案 0 :(得分:0)
如果您想为访客用户提供不同的辅助功能,您应该查看Zend_Acl。以下两个链接可以为您提供帮助:http://framework.zend.com/manual/1.12/en/learning.multiuser.authorization.html,Zend Auth and ACL。
答案 1 :(得分:0)
这对我有用:
public function _getGuestPremision()
{
$_acl = new Zend_Acl();
$_acl->add(new Zend_Acl_Resource('ref'));
$_acl->add(new Zend_Acl_Resource('downloadendnote'),'ref');
$_acl->add(new Zend_Acl_Resource('downloadmed','ref');
$_acl->add(new Zend_Acl_Resource('downloadris','ref');
$_acl->addRole(new Zend_Acl_Role('guest'));
$_acl->allow('guest','ref','downloadendnote');
$_acl->allow('guest','ref','downloadmed');
$_acl->allow('guest','ref','downloadris');
return $_acl ;
}
public function preDispatch()
{
$this->$_gAcl = _getGuestPremision();
if(!$this->_auth->hasIdentity())
{
if(!$_gAcl->isAllowed('guest','ref','downloadendnote'))
{
return $this->_helper->redirector('login','login');
}
if(!$_gAcl->isAllowed('guest','ref','downloadmed'))
{
return $this->_helper->redirector('login','login');
}
if(!$_gAcl->isAllowed('guest','ref','downloadris'))
{
return $this->_helper->redirector('login','login');
}
}
if(!isset($userInfo["member_id"]) || strlen($userInfo["member_id"])==0)
{
return $this->_helper->redirector('forbidden','login');
}
$this->_accessType=2;
}