【问题标题】:Rights modules uses a different application instance权限模块使用不同的应用程序实例
【发布时间】:2013-04-16 10:23:45
【问题描述】:

我正在开发一个 Yii 应用程序,它使用多个模块,包括用于访问控制的权限模块。它们都驻留在同一个“模块”文件夹中,并在同一个 config/main.php 文件中进行配置。并且应用程序只有一个入口脚本。

但是,我注意到 Rights 模块使用不同的应用会话,而所有其他模块使用另一个应用会话。由于这个原因,用户会话不与权限共享。

有没有人在使用 yii 模块时遇到过这样的问题?请帮忙。谢谢!

我的配置文件:

'rights'=>array(
            'debug' => true,
            'superuserName'         => 'Super Administrator', // Name of the role with super user privileges.                       
            'authenticatedName'     => 'Customer', // 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'     => true, // Whether to enable data for business rules.
            'displayDescription'    => false, // Whether to use item description instead of name.
            'flashSuccessKey'       => 'success', // Key to use for setting success flash messages.
            'flashErrorKey'         => 'error', // Key to use for setting error flash messages.
            //'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.
        ),

【问题讨论】:

  • 代码应该有问题。你能贴一些代码让我判断吗?但我认为不同的会话不是问题,因为根据我的理解这是不可能的。
  • 我认为当您尝试访问权限模块时更有可能没有实例化它......例如,如果在您的控制器访问规则中,您正在引用用户模块,您会需要先确保模块已被 UserIdentity 引用...
  • 大家好,感谢 cmets。我已经用我的配置详细信息更新了这个问题。权限模块也包含在系统中的任何其他模块中。奇怪的是,权限使用的是完全不同的应用程序实例,而所有其他模块都使用通用的应用程序实例。我通过检查应用程序 ID (Yii::app()->id) 确认了这一点

标签: yii rights


【解决方案1】:

经过两天的尝试,我找到了解决方案。

我注意到它在系统中使用了两个不同的键前缀(stateKeyPrefix)。一个用于权利,另一个用于其他模块。这可以配置为在主配置文件中使用单键前缀。

'user'=>array(
            'class'=>'RWebUser',
            'allowAutoLogin'=>true, // enable cookie-based authentication
            'stateKeyPrefix'=>'f298d9729c7408c3d406db95a9639204', // some random value
    ),

希望这能帮助遇到同样问题的人。

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    相关资源
    最近更新 更多