Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Zend-Framework中创建动态Acl(Acl检查列表)_Php_Zend Framework - Fatal编程技术网

Php 在Zend-Framework中创建动态Acl(Acl检查列表)

Php 在Zend-Framework中创建动态Acl(Acl检查列表),php,zend-framework,Php,Zend Framework,我正在尝试在zend框架中构建一个基于组的acl。基本上有三个角色:管理员、来宾和用户。用户角色将有不同的组。它的工作原理是我有一个模块/控制器的检查列表,使用检查列表管理员的操作将被允许创建组。组可以类似于编辑器(角色也将是编辑器的用户)。此组将保存在表组(组id、组名称)的数据库中,所选资源将保存在表资源(资源id、资源、组id)中。资源将以类似模块:控制器:操作(例如:用户:用户:登录)的格式保存 我想知道的是,我想做的是正确的方法,还是不正确,如果它有开销或任何建议,你可以张贴 clas

我正在尝试在zend框架中构建一个基于组的acl。基本上有三个角色:管理员、来宾和用户。用户角色将有不同的组。它的工作原理是我有一个模块/控制器的检查列表,使用检查列表管理员的操作将被允许创建组。组可以类似于编辑器(角色也将是编辑器的用户)。此组将保存在表组(组id、组名称)的数据库中,所选资源将保存在表资源(资源id、资源、组id)中。资源将以类似模块:控制器:操作(例如:用户:用户:登录)的格式保存

我想知道的是,我想做的是正确的方法,还是不正确,如果它有开销或任何建议,你可以张贴

class App_AccessCheck extends Zend_Controller_Plugin_Abstract{

public function preDispatch(Zend_Controller_Request_Abstract $request)
{    
    if(!$this->_acl->isAllowed(Zend_Registry::get('role'),"Controller","Action")){  

            $request->setModuleName('user')
                    ->setControllerName('user')
                    ->setActionName('login');
        }
}

class App_Acl extends Zend_Acl
{

    public function __construct()
    {   
       $this->addRole(new Zend_Acl_Role('guest'));
       $this->addRole(new Zend_Acl_Role('user'));
       $this->addRole(new Zend_Acl_Role('admin'));  
       $this->add(new Zend_Acl_Resource('Controller'))
             ->add(new Zend_Acl_Resource('Controller'), 'Action');
        $resource = new App_Resource();
        $params = $resource->getResource(); 
        $this->allow('user', 'Controller', 'Action', new App_ActionAssertion($params));
    }    

    public function isAllowed($role = null, $resource = null, $privilege = null)
    {
        // by default, undefined resources are allowed to all
        if (!$this->has($resource)) {
            $resource = 'nullresources';
        }
        return parent::isAllowed($role, $resource, $privilege);
    }

}

class App_Resource extends Zend_Controller_Request_Abstract{  

    protected $params;
    public function preDispatch(Zend_Controller_Request_Abstract $request)
        {
        $module = $request->getModuleName();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        $params = $module.":".$controller":".$action;
        $this->setParams($params);
        }

    public function getParams()
    {
        return $params;
                // String representing current module:controller:action
    }   
}

class App_ActionAssertion implements Zend_Acl_Assert_Interface
{  

    //this class will check the access of the group to the particular resource in the  database table: resource  based on the params passed
       //admin will be allowed all privilege
    //return true/false 
}

我想是在头顶上。您可以重用现有的解决方案,例如目录服务器,并管理其中的用户和角色。可能会帮上大忙我研究过那张幻灯片,但是我没有完全从缓存部分获得缓存和查询。@Rohan会就此提出一个问题。@lznogood我很好地使用了acl。当您的查询次数较少时,性能似乎不会因查询而降低,但问题是当您在cms级别这样的工作时如何处理100多个操作和控制器,这可能是一个问题,所以我正在寻找更好的解决方案。因此,我认为任何人都可能给出更好的解决方案。