2011-01-31 63 views
1

我正在使用auth組件,並且我不希望登錄頁面在用戶登錄後纔可訪問,只能由匿名用戶訪問。我可以在我的登錄方法中完成此操作?我已經試過這樣:CakePHP驗證組件:如何檢查某人是否已登錄?

if (isset($this->Auth->user('id')) { 
    $this->redirect('/profile/'); 
} 

但我得到以下錯誤:

Fatal error: Can't use method return value

+0

爲了將來的參考,這裏的主要錯誤是由於對非變量的東西使用了`isset()`。此外,還有一個缺失的結束括號。 – 2012-10-11 00:24:19

回答

3
if ($this->Session->check('Auth.User')){ 
    $this->redirect('/profile/'); 
} 
+0

非常感謝:) – geoffs3310 2011-01-31 14:46:54

10

的驗證組件實際上是當用戶登錄檢查提供a method

$this->Auth->loggedIn(); 

有六種其他的方式來檢查,但這是最好的,因爲它抽象aw執行認證會話。另外,它更容易閱讀。