I got the following set-up in my frontend\models\User:
class User extends ActiveRecord implements IdentityInterface
{
public static function findIdentity($id)
{
return static::find($id);
}
public function getId()
{
return $this->id;
}
public function getAuthKey()
{
return $this->authKey;
}
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
}
Now, when i’m going to site/logout, i get the following error:
The scope method "frontend\models\User::getId()" must be public and static.
If i make this method static, i get (off course) the error that IdentityInterface expects that getId() is non-static. So where does this error come from? As far as i see i think it sees the getId() as a scope.
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the email and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
private $_id;
public function authenticate()
{
$member=Members::model()->findByAttributes(array('email'=>trim($this->username)));
if($member===null){
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
elseif($member->password !== md5(trim($this->password))){
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
elseif($member->activation_date === null){
$this->errorCode = 11;
}
elseif($member->status != 1){
$this->errorCode = 10;
}
else
{
$this->_id=$member->id;
$this->setState('username', $member->username);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
public function setId($id)
{
$this->_id = $id;
}
}