2015-10-19 14 views
0

我在更改服務器後登錄時出現此錯誤。Yii進行身份驗證,使用此時不在對象上下文中

Fatal error: Using $this when not in object context

在accountController.php:

$model->attributes=$_POST['Account']; 
if ($model->validate() && $model->login()) { 
    ... 
} 

在account.php

public $email; 
public $password; 
private $_identity; 
..... 
public static function authenticate() 
{ 
    $this->_identity = new UserIdentity(
     $this->email, 
     $this->password 
    ); 
} 

_indentity,電子郵件地址和密碼不在對象範圍內,怎麼說有可能嗎?

回答

2

靜態方法中不能使用$this。靜態方法不能在一個對象上運行,它們只是一個命名空間的函數。

也許你的函數不應該被標記爲靜態的?

或者可能您的$_identity應該是靜態的。在這種情況下,您將可以通過myClass::$_identity

+0

訪問它謝謝,是爲了。現在正在工作,但很奇怪,因爲在其他服務器上工作。 –

相關問題