2017-08-04 119 views
0
  1. 工作我有僱員表,其結構如下:

EMPID

名字
用戶名
密碼驗證未在yii2

  • 現在在應用程序組件中,我已經包含了我的自定義類,如下所示:

    '用戶'=> [ 'identityClass'=> '應用程序\模型\僱員', 'enableSession'=>真, ],

  • 我已經實現在僱員模型FOLL方法如下:

    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(); }

    公共靜態函數findByUsername($用戶名) { 返回自:: findOne([ '用戶名'=> $用戶名]); }

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

  • 而在LoginForm模型中,我有以下內容。用戶,我已包括 自定義類員工。

    公共功能的getUser() { 如果($這 - > _用戶===假) { $這 - > _用戶=僱員:: findByUsername($這個 - >用戶名); }

    return $this->_user; 
    

    }

  • 現在,當我嘗試登錄,並提供用戶名和密碼,它提供了FOLL錯誤:

    財產來源不明 - 警予\基地\ UnknownPropertyException

    未知財產:app \ models \ Employee ::用戶名

    回答

    0

    注意您的列名中的情況 - 這應該與模型中的屬性相同。 ie:替換 - $ this-> usename to $ this-> Username;