Yii::app()->getModule('user') 正在返回'Trying to get property of non-object'



>我有一个问题,比如

Yii::app()->getModule('user') 没有返回正确的值 view/layout/main.php

但是我有一个不同的情况,我不能树脂它,它是使用右扩展。在主配置中

    'application.models.*',
    'application.components.*',
    'application.modules.rights.*',
    'application.modules.rights.components.*',

        '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.
        'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages.
        'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages.
        'install'=>false, // Whether to enable installer.
        'debug'=>false, // Whether to enable debug mode. 
    ),

然后我需要更新此应用程序以使用用户扩展。我正在尝试,结果是:

 Trying to get property of non-object 

     <?php $this->widget('zii.widgets.CMenu',array(
         'items'=>array(
             array('url'=>Yii::app()->getModule('user')->loginUrl, 'label'=>Yii::app()->getModule('user')->t("Login"), 'visible'=>Yii::app()->user->isGuest),


<更新>
现在我得到了不同的错误:

Trying to get property of non-object 
public function tableName()
 {
     return Yii::app()->getModule('user')->tableUsers;
 }
在\受保护\模块\用户\

模型\用户.php(41)

我在配置主中的代码我更新如下:

        'modules'=>array(
        'user'=>array(
            'tableUsers' => 'tbl_users',
            'tableProfiles' => 'tbl_profiles',
            'tableProfileFields' => 'tbl_profiles_fields',

知道我的错在哪里吗?*如果我的语法不好,请看。

SOLVED

在配置主中

    '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.
        'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages.
        'flashErrorKey'=>'RightsError', // 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.
        'debug'=>false, // Whether to enable debug mode. 
    ),
    'user'=>array(
        'hash' => 'md5',
        'tableUsers' => 'tbl_users',
        'tableProfiles' => 'tbl_profiles',
        'tableProfileFields' => 'tbl_profiles_fields',

并且不要更改模块中的任何内容。它的作品,就像魔术一样。哈哈

最新更新