我在更改服务器后登录时出现此错误。
在accountController.php:致命错误:当不在对象上下文中使用$this
$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