当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Acl::add方法代码示例

本文整理汇总了PHP中Zend_Acl::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Acl::add方法的具体用法?PHP Zend_Acl::add怎么用?PHP Zend_Acl::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Acl的用法示例。


在下文中一共展示了Zend_Acl::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * (non-PHPdoc)
  * @see Zend_Application_Resource_ResourceAbstract#init()
  */
 public function init()
 {
     $this->_acl = new Zend_Acl();
     // static roles
     $this->_acl->addRole(new Zend_Acl_Role('all'));
     $this->_acl->addRole(new Zend_Acl_Role('anonymous'), 'all');
     $this->_acl->addRole(new Zend_Acl_Role('identified'), 'all');
     // dinamic roles
     foreach ($this->_roles as $roleName) {
         if (!$this->_acl->hasRole($roleName)) {
             $this->_acl->addRole(new Zend_Acl_Role($roleName), 'identified');
         }
     }
     //        var_dump($this->_resources);exit;
     // rules
     foreach ($this->_resources as $module => $grants) {
         $module = strtolower($module);
         $this->_acl->add(new Zend_Acl_Resource($module));
         foreach ($grants as $controller => $grant) {
             $controller = strtolower($controller);
             foreach ($grant as $action => $roles) {
                 $resource = $controller . self::RESOURCE_SEPARATOR . $action;
                 foreach (explode(',', $roles) as $role) {
                     if (!empty($role)) {
                         $this->_acl->allow(trim($role), $module, $resource);
                     }
                 }
             }
         }
     }
     Zend_Registry::set('acl', $this->_acl);
     return $this->_acl;
 }
开发者ID:ramonornela,项目名称:trilhas,代码行数:37,代码来源:Acl.php

示例2: __construct

 public function __construct()
 {
     $acl = new Zend_Acl();
     //ролі
     $acl->addRole(new Zend_Acl_Role('guest'));
     //user наслідує усі параметри guest
     $acl->addRole(new Zend_Acl_Role('user'), 'guest');
     $acl->addRole(new Zend_Acl_Role('admin'));
     //ресурси - доступні контролери
     $acl->add(new Zend_Acl_Resource('users'));
     $acl->add(new Zend_Acl_Resource('index'));
     //дозвіл
     $acl->deny();
     //заборонити доступ всім
     $acl->allow('admin', null);
     //дозволити доступ admin-у до всього
     //users це resource - контролер
     // далі $privilege - екшн
     $acl->allow('guest', 'users', array('login', 'registration', 'confirm'));
     $acl->allow('guest', 'index');
     $acl->allow('user', 'users', array('logout'));
     $acl->deny('user', 'users', array('login', 'registration'));
     //глобальний доступ до змінної
     //щоб використати у видах
     Zend_Registry::set('acl', $acl);
     /*
             //isAllowed() - чи має доступ $role до $resourse і $privilege
             //$resource - контролер
             //$privilege - екшн
             if($acl->isAllowed($role, $resource, $privilege)){
                 
             } */
 }
开发者ID:Vika1994,项目名称:comments,代码行数:33,代码来源:Acl.php

示例3: __construct

 /** The constuctor for the class
  * @access public
  * @param Zend_Acl $aclData
  * @param $roleName string
  * @return void
  **/
 public function __construct(Zend_Acl $aclData, $roleName = 'public')
 {
     $this->_roleName = $roleName;
     if (NULL !== $aclData) {
         $this->setAcl($aclData);
     }
     $front = Zend_Controller_Front::getInstance();
     /** If an error handler hasn't been setup in the front controller, setup one */
     if (!$front->getParam('noErrorHandler') && !$front->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
         // Register with stack index of 100
         $front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
     }
     /** Allow error handler in the acl */
     $errorHandler = Zend_Controller_Front::getInstance()->getPlugin('Zend_Controller_Plugin_ErrorHandler');
     $defaultErrorModule = $errorHandler->getErrorHandlerModule();
     $defaultErrorController = $errorHandler->getErrorHandlerController();
     $defaultErrorAction = $errorHandler->getErrorHandlerAction();
     if (NULL !== $defaultErrorModule && $defaultErrorModule != 'default') {
         if (!$this->getAcl()->has($defaultErrorModule)) {
             require_once 'Zend/Acl/Resource.php';
             $this->_acl->add(new Zend_Acl_Resource($defaultErrorModule));
             $this->_acl->add(new Zend_Acl_Resource($defaultErrorModule . ':' . $defaultErrorController, $defaultErrorModule));
             $this->_acl->allow($this->_roleName, $defaultErrorModule . ':' . $defaultErrorController, $defaultErrorAction);
         }
     } else {
         if (!$this->getAcl()->has($defaultErrorController)) {
             $this->_acl->add(new Zend_Acl_Resource($defaultErrorController));
         }
         $this->_acl->allow($this->_roleName, $defaultErrorController, $defaultErrorAction);
     }
     $this->setDeniedAction('denied', $defaultErrorController, $defaultErrorModule);
 }
开发者ID:lesleyauk,项目名称:findsorguk,代码行数:38,代码来源:Acl.php

示例4: init

 /**
  * Hook into action controller initialization
  *
  * @return void
  */
 public function init()
 {
     // add resource for this controller
     $controller = $this->getAction()->getRequest()->getControllerName();
     if (!$this->_acl->has($controller)) {
         $this->_acl->add(new Zend_Acl_Resource($controller));
     }
 }
开发者ID:lesleyauk,项目名称:findsorguk,代码行数:13,代码来源:Acl.php

示例5: preDispatch

 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     try {
         $module = $request->getModuleName();
         if ($module == 'admin') {
             $moduleList = new Zend_Session_Namespace('moduleList');
             $userInfo = new Zend_Session_Namespace('userInfo');
             $module = $moduleList->module;
             $allowed_module = $userInfo->module_list;
             //generating all resources
             $acl = new Zend_Acl();
             //generating user permission
             $acl->addRole(new Zend_Acl_Role('admin'));
             $acl->addRole(new Zend_Acl_Role('anonymous'));
             $acl->add(new Zend_Acl_Resource('index'));
             $acl->add(new Zend_Acl_Resource('ajax'));
             $acl->allow('admin', 'index');
             $acl->allow('admin', 'ajax');
             if (!empty($module)) {
                 foreach ($module as $value) {
                     if (!$acl->has($value['controller'])) {
                         $acl->add(new Zend_Acl_Resource($value['controller']));
                     }
                     if (in_array($value['id'], $allowed_module)) {
                         if ($value['action'] != null) {
                             $acl->allow('admin', $value['controller'], $value['action']);
                         } else {
                             $acl->allow('admin', $value['controller']);
                         }
                     }
                 }
             }
             //allowing anonymous user to get into the login page
             $acl->allow('anonymous', 'index', 'index');
             $acl->allow('anonymous', 'index', 'login');
             $auth = Zend_Auth::getInstance();
             if ($auth->hasIdentity()) {
                 $role = 'admin';
             } else {
                 $role = 'anonymous';
             }
             $controller = $request->controller;
             $action = $request->action;
             if (!$acl->isAllowed($role, $controller, $action)) {
                 $request->setModuleName('admin');
                 $request->setControllerName('error');
                 $request->setActionName('acl');
                 $request->setParam('type', 1);
             }
         }
     } catch (Zend_Acl_Exception $e) {
         $request->setModuleName('admin');
         $request->setControllerName('error');
         $request->setActionName('acl');
         $request->setParam('type', 2);
     }
 }
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:57,代码来源:AccessPlugin.php

示例6: __construct

 public function __construct()
 {
     $acl = new Zend_Acl();
     $acl->addRole(new Zend_Acl_Role('guest'));
     $acl->addRole(new Zend_Acl_Role('admin'));
     $acl->add(new Zend_Acl_Resource('admin'));
     $acl->add(new Zend_Acl_Resource('index'));
     $acl->deny();
     $acl->allow('admin', null);
     $acl->allow('guest', 'admin', array('login'));
     $acl->allow('guest', 'index');
     Zend_Registry::set('acl', $acl);
 }
开发者ID:p-artem,项目名称:zend.site,代码行数:13,代码来源:Acl.php

示例7: _setupAcl

 /**
  * Setup the ACL
  *
  * @return void
  */
 protected function _setupAcl()
 {
     if (!$this->_acl->has($this)) {
         $this->_acl->add($this);
         $this->_setupPrivileges();
     }
 }
开发者ID:slak,项目名称:Firal,代码行数:12,代码来源:ServiceAbstract.php

示例8: checkAccess

 public function checkAccess(Zend_Controller_Request_Abstract $request)
 {
     $resource = new User_Model_Acl_Resource();
     $resource->getPrivileges($request);
     if (!$resource->privileges || !$resource->resource_id) {
         //error in getting resource privileges or nobody is allowed access, deny access and redirect to forbidden
         return false;
     }
     $acl = new Zend_Acl();
     $acl->add(new Zend_Acl_Resource($resource->resource_id));
     foreach ($resource->privileges as $key => $privilege) {
         if (!$acl->hasRole($privilege["role_id"])) {
             $acl->addRole(new Zend_Acl_Role($privilege["role_id"]));
             $acl->allow($privilege["role_id"], $resource->resource_id);
         }
     }
     $authorization = Zend_Auth::getInstance();
     if ($authorization->hasIdentity()) {
         $user = $authorization->getIdentity();
         if ($acl->hasRole($user['role_id']) && $acl->isAllowed($user['role_id'], $resource->resource_id)) {
             //role has access
             return true;
         }
         //user role does not have access to this resource
         return false;
     } else {
         $aclrole = new User_Model_Acl_Role();
         $aclrole->getDefaultRole();
         if (!$aclrole->default_role || !$acl->hasRole($aclrole->default_role) || !$acl->isAllowed($aclrole->default_role, $resource->resource_id)) {
             //redirect to login
             return false;
         }
     }
     return true;
 }
开发者ID:ankuradhey,项目名称:laundry,代码行数:35,代码来源:Init.php

示例9: setAcl

 public function setAcl(Zend_Acl $acl)
 {
     if (!$acl->has($this->getResourceId())) {
         $acl->add($this)->deny(Model_Role::GUEST, $this, array('view', 'delete'));
     }
     $this->_acl = $acl;
 }
开发者ID:kminkov,项目名称:Blog,代码行数:7,代码来源:Log.php

示例10: getAcl

 public function getAcl()
 {
     Zend_Registry::get('log')->info(__METHOD__);
     $acl = new Zend_Acl();
     $acl->addRole(new Zend_Acl_Role(1));
     $acl->add(new Zend_Acl_Resource('As'));
     $acl->add(new Zend_Acl_Resource('Bs'));
     $acl->add(new Zend_Acl_Resource('A'));
     $acl->add(new Zend_Acl_Resource('B'));
     $acl->allow(1, 'As');
     //$acl->allow(1, 'Bs');
     $acl->allow(1, 'A', 'edit', new App_Acl_Assert_ResourceAccess());
     $acl->allow(1, 'A', 'edit:all');
     $acl->allow(1, 'A', 'delete', new App_Acl_Assert_ResourceAccess());
     $acl->allow(1, 'A', 'delete:mine');
     return $acl;
 }
开发者ID:nandinibhaduri,项目名称:zendAcl,代码行数:17,代码来源:User.php

示例11: addAllResources

 /**
  * @return void
  */
 public function addAllResources()
 {
     $query = Doctrine_Query::create()->select('c.name, m.name')->from('Model_Entity_Controller c')->leftJoin('c.Module m')->useQueryCache(Kebab_Cache_Query::isEnable());
     $resources = $query->execute();
     foreach ($resources as $resource) {
         parent::add(new Zend_Acl_Resource($resource->Module->name . '_' . $resource->name));
     }
 }
开发者ID:esironal,项目名称:kebab-project,代码行数:11,代码来源:Acl.php

示例12:

 function __construct($class = NULL)
 {
     $CI =& get_instance();
     $CI->load->library('zend');
     $CI->zend->load('Zend/Acl');
     $CI->zend->load('Zend/Acl/Role');
     $CI->zend->load('Zend/Acl/Resource');
     $acl = new Zend_Acl();
     //Add the Role
     $acl->addRole(new Zend_Acl_Role('NU'));
     $acl->addRole(new Zend_Acl_Role('memUser'), 'member');
     //Add Resource
     $acl->add(new Zend_Acl_Resource('users_login'));
     $acl->add(new Zend_Acl_Resource('users_profile'), 'users_login');
     $acl->allow('member', 'users_login');
     $acl->allow('memUser', 'users_profile');
 }
开发者ID:JosephMokano,项目名称:somu-nhr,代码行数:17,代码来源:Zacl.php

示例13: testgetResources

 /**
  * @group ZF-8468
  */
 public function testgetResources()
 {
     $this->assertEquals(array(), $this->_acl->getResources());
     $this->_acl->add(new Zend_Acl_Resource('someResource'));
     $this->_acl->add(new Zend_Acl_Resource('someOtherResource'));
     $expected = array('someResource', 'someOtherResource');
     $this->assertEquals($expected, $this->_acl->getResources());
 }
开发者ID:nbcutech,项目名称:o3drupal,代码行数:11,代码来源:AclTest.php

示例14: __construct

 public function __construct()
 {
     $acl = new Zend_Acl();
     // добавляем роли
     $acl->addRole(new Zend_Acl_Role('guest'));
     $acl->addRole(new Zend_Acl_Role('admin'));
     // добавляем ресурсы
     $acl->add(new Zend_Acl_Resource('sites'));
     $acl->add(new Zend_Acl_Resource('index'));
     $acl->add(new Zend_Acl_Resource('logs'));
     $acl->add(new Zend_Acl_Resource('auth'));
     $acl->add(new Zend_Acl_Resource('maps'));
     $acl->add(new Zend_Acl_Resource('best'));
     $acl->add(new Zend_Acl_Resource('news'));
     // если нет роли то все запрещаем
     $acl->deny();
     // админу по умолчанию разрешено все
     $acl->allow('admin', null);
     // гостю только контроллер с экшеном для входа
     $acl->allow('guest', 'auth', array('index', 'check'));
     $acl->allow('guest', 'maps', array('cronmaps'));
     $acl->allow('guest', array('module' => 'best', 'controller' => 'news'), array('scan', 'redirect'));
     // если надо запретить экшены в разрешенном контроллере
     /*$acl->deny('user', 'users', array(
           'login', 'registration'
       ));
        * 
        */
     Zend_Registry::set('acl', $acl);
 }
开发者ID:MichaelGogeshvili,项目名称:strap,代码行数:30,代码来源:Acl.php

示例15: getAcl

 /**
  * Get ACL lists
  * 
  * @return Zend_Acl
  */
 public function getAcl()
 {
     if (null === $this->_acl) {
         $acl = new Zend_Acl();
         $acl->add(new Zend_Acl_Resource('admin'))->add(new Zend_Acl_Resource('kap'))->add(new Zend_Acl_Resource('members'))->addRole(new Zend_Acl_Role('guest'))->addRole(new Zend_Acl_Role('kap'), 'guest')->addRole(new Zend_Acl_Role('admin'), 'kap')->deny()->allow('admin', 'admin')->allow('admin', 'members')->allow('admin', 'kap')->allow('kap', 'kap')->allow('kap', 'members')->allow('guest', 'members', array('index', 'team', 'player', 'turnir', 'old', 'regno'));
         $this->_acl = $acl;
     }
     return $this->_acl;
 }
开发者ID:smalyshev,项目名称:chgk-teams,代码行数:14,代码来源:Auth.php


注:本文中的Zend_Acl::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。