Hallo,
ich habe versucht CUserIdentity um ein Feld zu erweitern, wie es im cookbook steht.
das hier ist mein code:
class UserIdentity extends CUserIdentity { private $isadmin; /** * Authenticates a user. * The example implementation makes sure if the username 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. */ public function authenticate() { $condition = new CDbCriteria; $condition->condition = "name = '$this->username'"; $user = User::model()->find($condition); if($user == null){ $this->errorCode=self::ERROR_USERNAME_INVALID; $this->setState("isadmin", false); }else if($user->password !== $this->password){ $this->errorCode=self::ERROR_PASSWORD_INVALID; $this->setState("isadmin", false); }else{ $this->errorCode=self::ERROR_NONE; $this->setState("isadmin", $user->isadmin != 0); } $this->isadmin = $this->getState("isadmin", false); return !$this->errorCode; } public function getIsadmin(){ return $this->isadmin; } }
iden teil mit der privaten variable habe ich hinzugefügt, da die variante mit setState nicht ging.
Ich bekomme eine CException wenn ich foglendes versuche:
<= Yii::app()->user->isadmin ? "Admin" : "kein Admin" =>
Was mach ich denn falsch?