2012-01-31 45 views
1

我使用cakephp,我想創建登錄元素。
這種佈局工作爲: 1時,我應該登錄時,該元素應該顯示這個代碼:我如何訪問元素中的用戶信息

echo $this->Form->create('User', array('action' => 'login')); 
echo $this->Form->inputs(array(
    'legend' => __('Login', true), 
    'username', 
    'password' 
)); 
echo $this->Form->end('Login'); 

2 - 當我登錄和元素應該顯示我的信息,如用戶名或電子郵件。 如果我使用視圖我可以使用$this->Auth但我不能使用這種方式,有另一種方式的元素,謝謝。

回答

0

你可以得到從會議內容的loggedIn用戶的個人信息,如:

 

//check if user is logged in 
if (!$this->Session->read('Auth.User.id')) { 
    //show your login form here 
} 
else { 
    //the user is loggedin 
    //get the loggedin users's information from session 
    $username = $this->Session->read('Auth.User.username'); 
    $email = $this->Session->read('Auth.User.email'); 
} 
 

您是不是要找類似的東西

+0

我認爲是不把該邏輯的正確的地方。您應該閱讀控制器中的登錄狀態,然後將用戶數據傳遞到視圖中,然後根據是否存在該視圖來決定顯示。 – Dunhamzzz 2012-01-31 09:57:52

相關問題