2012-11-28 41 views
0

我正在一个网站上工作,在CV部分用户有一些文章只有登录用户才能下载。我想对登录Action或preDispatch()进行更改以设置来宾用户下载文章的会话。为Zend框架中的某些操作设置的会话

有人可以告诉我怎么做,或给我一些参考链接?

这里是我的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

这为我工作:

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; 

}