【问题标题】:Use customer table for role based access control instead of user in yii2使用客户表进行基于角色的访问控制,而不是 yii2 中的用户
【发布时间】:2016-03-06 11:46:47
【问题描述】:

我想在yii2中使用表login_info而不是表用户来在前端部分创建不在后端部分的成员活动。此外,我在表 login_info 中有角色,例如:health-post、hospital、fchv 等,不能从 user_id 管理,但可以从 user_name 管理。你对 yii2 有什么想法吗?

【问题讨论】:

    标签: php mysql yii2 rbac yii2-rbac


    【解决方案1】:

    如果您只想更改表名(并且表的架构类似于 yii 用户表),您可以轻松(重新)定义函数 tableName 在您的

    frontend\models User.php 例如:这样

    namespace frontend\models;
    
    use yii\models\web\User as BaseUser;
    
    class User extends BaseUser
    {
        public static function tableName()
        {
            return  'yuor_table_user';
        }
    }
    

    但是,如果您想根据您的特定功能定义您的用户组件,您应该创建一个新的适当的用户类来实现身份接口 您可以查看authentication - security guidethe user interfaceyii user class 供参考和示例

    这不是一份简单的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-22
      • 2018-07-11
      • 2019-12-08
      • 2012-06-25
      • 2011-11-02
      • 2016-05-06
      • 2013-03-22
      • 1970-01-01
      相关资源
      最近更新 更多