Yii 用户权限扩展



我已经安装了 Yii 权限扩展,这是我安装后的代码,安装后会创建数据库表。

'modules'=>array(
        // uncomment the following to enable the Gii tool
            'rights'=>array( 
             'superuserName'=>'Admin',   // Name of the role with super user privileges.    
             'authenticatedName'=>'Authenticated',  //// Name of the authenticated user role.
                  'userIdColumn'=>'id',// Name of the user id column in the database.   
                   'userNameColumn'=>'username', //     Name of the user name column in the database.  
                   'enableBizRule'=>true, // Whether to enable authorization item business rules.    
                   'enableBizRuleData'=>false, //Whether to enable data for business rules.   
                         'displayDescription'=>true,  // Whether to use item description instead of name.    '
                          // Key to use for setting success flash messages.  
                            'flashErrorKey'=>'RightsError',  
                            / Key to use for setting error flash messages.    
                          //  'install'=>true,    // Whether to install rights.    
                            'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested.   
                              'layout'=>'rights.views.layouts.main',  // Layout to use for displaying Rights.    
                              'appLayout'=>'application.views.layouts.main', //Application layout.  
                                 'cssFile'=>'rights.css',   // Style sheet file to use for Rights.    '
                                 'install'=>false,  // Whether to enable installer.
                                        'debug'=>false,
                    ),

        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'1234',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'=>array('127.0.0.1','::1'),
        ),
    ),

但是当我输入网址http://localhost/rightsTest/index.php/rights时,它说

Error 403
There must be at least one superuser!

我尝试了很多东西,但找不到答案。感谢您的帮助。

您是否有一个带有 id、用户名的用户表,并且您必须检查该表中是否至少有一条记录。因为权限选择用户表中的第一条记录作为管理员角色。

创建新的管理员用户。数据库中有一个"用户"表,它的权限是,使用您选择的"用户名","密码"输入您的管理员用户,不要忘记将"超级用户"和"状态"字段值设置为1%。

您尚未在配置文件中指定超级用户。

  1. 在 yii 安装中打开受保护>配置>主.php文件。
  2. 查找以下与权限配置相关的行。

        'rights'=>array( 
              'install'=>false, // Enables the installer. 
              'userNameColumn'=>'user_name',
              'userClass'=>'Users',
              'superuserName'=>'your_superuser_username'
        ),
    
  3. 输入您的超级用户用户名作为"超级用户名"的值。

  4. 保存主.php

并尝试重新加载权限。问题将得到解决。:)

注意:确保此处也正确指定了用户类和用户表user_name列。否则,您可能会面临另一个问题。祝您编码愉快!谢谢。

我有同样的问题,我在 RAuthorizer 中添加了我的超级用户名。 在权限/组件/RAuthorizer

$superusers = array('beautiful'); // Beautiful is my superadmin username
foreach( $users as $user )
$superusers[] = $user->name;
    if( $superusers===array() )
    throw new CHttpException(403, Rights::t('core', 'There must be at least one superuser!'));
    return $superusers;

它有效。

最新更新