【问题标题】:Yii::app()->getModule('user') is returning 'Trying to get property of non-object'Yii::app()->getModule('user') 正在返回“尝试获取非对象的属性”
【发布时间】:2015-03-11 01:59:29
【问题描述】:

我有一个问题

Yii::app()->getModule('user') is not returning the right value 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;
 }

在\protected\modules\user\models\User.php(41)中

我在 config main 中的代码更新如下:

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

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

【问题讨论】:

    标签: yii yii-extensions


    【解决方案1】:
    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',
    

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

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 2017-05-20
      • 2017-08-10
      • 2013-07-24
      相关资源
      最近更新 更多