ii身份验证,当不在对象上下文中时使用它


Yii authenticate, using this when is not in object context

我在更改服务器后登录时出现此错误。

致命错误:当不在对象上下文中使用$this

在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
    );
}

_identity, email和password不在对象上下文中,这是怎么可能的?

不能在静态方法中使用$this。静态方法不在对象上运行,它们只是一个类命名空间的函数。

也许你的函数不应该被标记为静态?

或者您的$_identity应该是静态的。在这种情况下,你可以通过myClass::$_identity

访问它