0
  1. I have Employee table whose structure is as follows:

EmpId
FirstName
LastName
Username
Password

  1. Now in application component I have included my custom class as follows:

    'user' => [ 'identityClass' => 'app\models\Employee', 'enableSession' => true, ],

  2. I have implemented foll methods in Employee model as follows:

    public static function findIdentityByAccessToken($token, $type = null) { throw new NotSupportedException(); }

    public function getId() { return $this->EmpId; }

    public function getAuthKey() { throw new NotSupportedException(); }

    public function validateAuthKey($authKey) { throw new NotSupportedException(); }

    public static function findByUsername($username) { return self::findOne(['Username'=>$username]); }

    public function validatePassword($password) { return $this->Password === $password; }

  3. And in LoginForm model, I have following. Insted of User, I have included custom class Employee.

    public function getUser() { if ($this->_user === false) { $this->_user = Employee::findByUsername($this->username); }

    return $this->_user;
    

    }

Now when I try to login and provide username and password, it gives the foll error:

Unknown Property – yii\base\UnknownPropertyException

Getting unknown property: app\models\Employee::username

Questions
  • 69
  • 1
  • 12

1 Answers1

0

Notice the Case in the column names in your - this should be the same as attributes in your model. ie: replace - $this->usename to $this->Username;

Kalu
  • 561
  • 2
  • 7