【问题标题】:Assign role to a user in Phalcon在 Phalcon 中为用户分配角色
【发布时间】:2014-03-12 03:34:03
【问题描述】:

我是 phalcon 的新手,我曾经学习过 invo 示例应用程序。在 security.php 我发现:

$auth = $this->session->get('auth');
        if (!$auth){
            $role = 'Guests';
        } else {
            $role = 'Users';
        }

有没有办法创建具有不同分配角色的用户组,如 joomla? 谢谢

【问题讨论】:

    标签: joomla phalcon user-roles


    【解决方案1】:

    你可以做的是,当用户登录时,设置会话如下:-

    $this->session->set('auth', array(
        'username' => $user->username,
        'power' => $user->power //Assuming that you have power assigned to each user
    ));
    

    现在,当您需要检查用户的角色时,您可以实现以下方法:-

    $auth = $this->session->get('auth');
    if(!$auth) {
        $role = 'Guest';
    } elseif($auth['power'] == 0) {
        $role = 'Admin';
    } elseif($auth['power'] == 2) {
        $role = 'Sub-Admin';
    } else {
        $role = 'User'; //If power equals to 1 or 2 then assign the role else assign normal user role
    }
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2010-10-09
      • 2021-06-29
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2016-03-09
      • 2018-08-21
      • 2019-06-04
      相关资源
      最近更新 更多