2012-07-04 71 views
0

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user訪問已登錄的用戶AuthComponent :: user()

有人可以幫助我理解這一點。

AuthComponent::user()方法只返回關於用戶的一些基本信息,而不是實際的用戶對象本身。

從軌道的到來,我習慣了一個滿載current_user對象

如果我想類似的東西,我應該做一個

$this->User->id = AuthComponent::user('id')

和使用?或者是已經有一個我可以使用的內置方法。

在此先感謝。

回答

0

我結束了做這樣的事情

# load current_user 
$this->loadModel('User'); 
$this->User->id = AuthComponent::user('id'); 
$user = $this->User->read(); 
$this->set('current_user',$user); 
2

如果向下滾動鏈接的文檔中的一點,你會認爲這是CakePHP的2.2,你可以在你的驗證設置現在使用Containable,所以你可以做這樣的事情:

public $components = array(
    'Auth' => array(
     'authenticate' => array(
      'Form' => array(
       'fields' => array('username' => 'email'), 
       'contain' => array('RelatedModel', 'RelatedModel') 
      ) 
     ) 
    ) 
); 
相關問題