ZendFramework插件类实例[角色控制]

<?
/**
 * ZendFramework插件类实例[角色控制]...
 * @author:PHP博客-技术-资源-技术站-面向对象 PHPCQ.com
 * 
 *
 */
class Plugin_Security extends Zend_Controller_Plugin_Abstract{
    
    protected 
$_acl;
    
    public function 
__construct($acl){
        
$this->_acl $acl;
    }
    
    public function 
dispatchLoopStartup($request){
        
        
$auth Zend_Auth::getInstance();
        
        
$role 'guest';
        
        if (
$auth->hasIdentity()) {
            
            
$role $auth->getIdentity()->role;
        }
        
$resource $request->getActionName();
        if (
$this->_acl->has($resource)) {
            
            if (!
$this->_acl->isAllowed($role,$resource)) {
                
                
$session = new Zend_Session_Namespace('ACLSecurity');
                
                
$session->uri $request->getRequestUri();
                
                
$request->setControllerName('index');
                
                
$request->setActionName('login');
            }
            
        }
        
        
    }
}
?>      
前端控制器注册插件
$front->registerPlugin(new Plugin_Security($acl));     
      
      
      
      
      

上一篇文章: ZendFramework身份验证实例 下一篇文章: 明天就要离开公司了

关于PHP博客

PHP blogger

博客-致力于分享PHP技术的开发心得, 记录站长生活的点点滴滴,PHP博客采用PHP 面向对象编程+Smarty模板引擎+Mysql数据库 开发(全站纯静态化与伪静态化)
QQ:334192009
电邮:admin@PHPdesigner.org

本站搜索

本站最新文章

博客最近档案

友情链接