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


PHP Zend_Auth::getRoleId方法代码示例

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


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

示例1: preDispatch

 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  By altering the
  * request and resetting its dispatched flag (via
  * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
  * the current action may be skipped.
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // reset role & resource
     Zend_Registry::set('Role', 'guest');
     Zend_Registry::set('Resource', '');
     // check if ErrorHandler wasn't fired
     if ($request->getParam('error_handler')) {
         return;
     }
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $pathInfo = $request->getPathInfo();
     $allow = false;
     if ($this->_auth->hasIdentity()) {
         $userId = $this->_auth->getIdentity();
         $roleId = $this->_auth->getRoleId();
         $rolesList = $this->_em->find('Roles', $roleId);
         $roleName = $rolesList->getRoleName();
         $role = new Zend_Acl_Role($roleName);
     } else {
         $roleName = 'guest';
         $role = new Zend_Acl_Role($roleName);
     }
     $resource = $action == '' ? trim($controller) . '/index' : trim($controller) . '/' . trim($action);
     $resource = $module == 'default' ? $resource : $module . "/" . $resource;
     // on main page resource might be empty
     if ($resource == '') {
         $resource = 'index/index';
     }
     // if resource not exist in db then check permission for controller
     if (!$this->_acl->has($resource) && $action != '') {
         $resource = trim($controller);
     }
     // check if user is allowed to see the page
     $allow = $this->_acl->isAllowed($role, $resource);
     if ($allow == false && $this->_auth->hasIdentity()) {
         // user logged in but denied permission
         $request->setModuleName('default');
         $request->setControllerName('error');
         $request->setActionName('forbidden');
         /* $this->_response->setHeader('Content-type', 'text/html');
                       $this->_response->setHttpResponseCode(403);
                       $this->_response->setBody('<h1>403 - Forbidden</h1>');
         
                       $this->_response->sendResponse(); */
     }
     Zend_Registry::set('Role', $role);
     Zend_Registry::set('Resource', $resource);
 }
开发者ID:uppaljs,项目名称:pakistan-vlmis-v2,代码行数:61,代码来源:Acl.php


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