0

我在一个网站上工作,在简历部分用户有一些只有登录用户才能下载的文章。我想对登录 Action 或 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;

    }
4

2 回答 2

0

如果您希望来宾用户具有不同的可访问性,您应该查看 Zend_Acl。这里有两个链接可以帮助您:http : //framework.zend.com/manual/1.12/en/learning.multiuser.authorization.html、Zend Auth 和 ACL

于 2012-11-28T13:44:06.760 回答
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;

}
于 2012-11-29T05:30:09.887 回答