UserIdentity

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?

Hi,

welche Version von Yii verwendest du denn? Das ganze muss ohne deine private Variable funktionieren, die Getter-Methode ist seit 1.0.3 ebenfalls nicht mehr nötig.

Was sagt die Exception denn?

also ich habe 1.0.3

und es war eine CException die sagt property not defined. in der magic get

Versuch mal, deine private Variable umzubenennen (z.B. $_isadmin).

Übrigens: Die Getter-Methode ist hier natürlich schon noch nötig. Nur wenn man Daten mit setState() speichert, braucht man sie jetzt nicht mehr.