2013-06-20 39 views

回答

2

MyWbuser。 php中的組件:

class MyWebUser extends CWebUser{ 

    private $_profile = null; 
    public $loginUrl='/'; 

    public function init(){ 
     parent::init(); 
     if(!$this->getIsGuest()){ 
      $this->_profile = User::model()->findByPk($this->getId()); 
     } 
    } 
    public function getProfile(){ 
     return $this->_profile; 
    } 
} 

在config.php:

'user' => array(
     'class' => 'MyWebUser', 
    ) 

然後你可以使用:

Yii::app()->user->profile->name 
+0

這是一個好主意)據我所知,而不是UserIdentity? – frops

+0

是的,它擴展了CWebUser – HarryFink

+0

謝謝哈里) – frops

1

試試這個將此代碼添加到您的UserIdentity身份驗證功能

$this->setState('email',$this->email); 

和使用,隨時隨地訪問電子郵件,如圖

Yii::app()->user->getState('email'); 
+0

這是一個好主意。謝謝你,Ninad)順便說一下,昨天的任務我coped =)@Ninad – frops

+0

好的乾杯:)這是什麼問題? – Ninad

+0

我使用模型用戶而不是RegisterForm) – frops