2016-07-14 7 views
0

내가 현재 사용자의 [group_id] => 1을 얻을 필요 "WebUser.group_id"확인되지 않은 속성은

echo Yii::app()->user->group_id

나는 쓸 때 :

print_r(Yii::app()->user); 

내가 얻을 :

WebUser Object ( 
    [_model:WebUser:private] => User Object ( 
     [_profile:protected] => Profile Object ( 
      [created_at] => 
      [created_by] => 
      [updated_at] => 
      [updated_by] => 
      [_new:CActiveRecord:private] => 
      [_attributes:CActiveRecord:private] => Array ( 
       [user_id] => 53 
       [firstname] => Garik 
       [lastname] => test_Lastname 
       [title] => test_title 
       [gender] => male 
       [street] => 
       [zip] => 
       [city] => 
       [country] => 
       [state] => 
       [birthday_hide_year] => 0 
       [birthday] => 2016-07-01 00:00:00 
       [about] => 
       [phone_private] => 
       [phone_work] => 
       [mobile] => 
       [fax] => 
       [im_skype] => 
       [im_msn] => 
       [im_icq] => 
       [im_xmpp] => 
       [url] => 
       [url_facebook] => 
       [url_linkedin] => 
       [url_xing] => 
       [url_youtube] => 
       [url_vimeo] => 
       [url_flickr] => 
       [url_myspace] => 
       [url_googleplus] => 
       [url_twitter] => 
      ) 
      [_related:CActiveRecord:private] => Array () 
      [_c:CActiveRecord:private] => 
      [_pk:CActiveRecord:private] => 53 
      [_alias:CActiveRecord:private] => t 
      [_errors:CModel:private] => Array () 
      [_validators:CModel:private] => 
      [_scenario:CModel:private] => update 
      [_e:CComponent:private] => Array ( 
       [onbeforedelete] => CList Object ( 
        [_d:CList:private] => Array ( 
         [0] => Array ( 
          [0] => ActivityModule 
          [1] => onActiveRecordDelete 
         ) 
         [1] => Array ( 
          [0] => FileModuleEvents 
          [1] => onBeforeHActiveRecordDelete 
         ) 
        ) 
        [_c:CList:private] => 2 
        [_r:CList:private] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
       ) 
      ) 
      [_m:CComponent:private] => 
     ) 
     [created_at] => 2016-06-17 10:50:57 
     [created_by] => 27 
     [updated_at] => 2016-06-22 09:15:25 
     [updated_by] => 27 
     [_new:CActiveRecord:private] => 
     [_attributes:CActiveRecord:private] => Array ( 
      [id] => 53 
      [guid] => 397272fb-ac4f-4df4-95e7-171b34e85e04 
      [wall_id] => 
      **[group_id] => 1** 
      [status] => 1 
      [super_admin] => 1 
      [username] => test2 
      [email] => [email protected] 

쓸 때 :

,210
echo Yii::app()->user->group_id 

는 오류가 발생합니다 :

CException: 
Undetermined property “WebUser.group_id” 

클래스 WEBUSER

<?php 

class WebUser extends CWebUser 
{ 

    /** 
    * Stores user model to not repeat the database query 
    * 
    * @var User 
    */ 
    private $_model; 

    /** 
    * Returns the users displayname 
    * 
    * Access it by Yii::app()->user->displayname 
    * 
    * @return String 
    */ 
    public function getDisplayName() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 
     return $user->displayName; 
    } 

    /** 
    * Returns the users e-mail address 
    * 
    * @return String 
    */ 
    public function getEmail() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 
     return $user->email; 
    } 

    /** 
    * Returns the language code of the user model 
    * 
    * @return String 
    */ 
    public function getLanguage() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 
     if ($user != null) 
      return $user->language; 
    } 

    /** 
    * Returns users guid 
    * 
    * @return String 
    */ 
    public function getGuid() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 
     return $user->guid; 
    } 

    /** 
    * Returns users authentication mode 
    * 
    * @return String 
    */ 
    public function getAuthMode() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 
     return $user->auth_mode; 
    } 

    /** 
    * Returns current user model 
    * 
    * @return type 
    * @throws CHttpException 
    */ 
    public function getModel() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 

     if ($user == null) 
      throw new CHttpException(500, 'Could not find logged in user!'); 

     return $user; 
    } 

    /** 
    * Reloads the user cached model 
    */ 
    public function reload() 
    { 
     $this->_model = null; 
    } 

    /** 
    * Checks if the user is admin 
    * 
    * Access it by Yii::app()->user->isAdmin() 
    * 
    * @return int 
    */ 
    public function isAdmin() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 

     if ($user->super_admin == 1) { 
      return true; 
     } 

     return false; 
    } 

    /** 
    * Checks if the can approve new users 
    * @todo Add caching support 
    * 
    * @return boolean 
    */ 
    public function canApproveUsers() 
    { 

     if ($this->isAdmin()) 
      return true; 

     $user = $this->loadUser(Yii::app()->user->id); 

     $adminGroups = GroupAdmin::model()->countByAttributes(array('user_id' => $user->id)); 
     if ($adminGroups != 0) { 
      return true; 
     } 

     return false; 
    } 

    /** 
    * Checks if the user can create a space 
    * 
    * @return boolean 
    */ 
    public function canCreateSpace() 
    { 
     return ($this->canCreatePrivateSpace() || $this->canCreatePublicSpace()); 
    } 

    /** 
    * Checks if the user can create public spaces 
    * 
    * @return boolean 
    */ 
    public function canCreatePublicSpace() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 

     if (Yii::app()->user->isAdmin()) { 
      return true; 
     } elseif ($user->group !== null && $user->group->can_create_public_spaces == 1) { 
      return true; 
     } 

     return false; 
    } 

    /** 
    * Checks if user can create private spaces 
    * 
    * @return boolean 
    */ 
    public function canCreatePrivateSpace() 
    { 
     $user = $this->loadUser(Yii::app()->user->id); 

     if (Yii::app()->user->isAdmin()) { 
      return true; 
     } elseif ($user->group !== null && $user->group->can_create_private_spaces == 1) { 
      return true; 
     } 

     return false; 
    } 

    /** 
    * Loads user model and store/cache it as class attribute 
    * 
    * @param Int $id 
    * @return User 
    */ 
    protected function loadUser($id = null) 
    { 

     if ($this->_model === null) { 
      if ($id !== null) { 
       $this->_model = User::model()->findByPk($id); 
      } else { 
       // Create Blank user 
       $this->_model = new User(); 
      } 
     } 
     return $this->_model; 
    } 

    /** 
    * If request is ajax, do not update auth status 
    * @override 
    */ 
    protected function updateAuthStatus() 
    { 
     if (Yii::app()->request->isAjaxRequest) 
      return; 

     parent::updateAuthStatus(); 


    } 

} 
+0

는 개인 재산이며이 될 것 액세스 할 수 –

답변

1

group_id 당신이 도달하려는 WebUser 개체의 속성이 아니라 속성은 아니다 User 모델의 Webuser에있는 private $_model.

그래서 코드는

Yii::app()->user->model->group_id; 

또는

이 GROUP_ID 보인다
Yii::app()->user->getModel()->group_id; 
관련 문제