【问题标题】:Authentication not working in yii2身份验证在 yii2 中不起作用
【发布时间】:2017-08-04 11:22:46
【问题描述】:
  1. 我有 Employee 表,其结构如下:

EmpId
名字

用户名
密码

  1. 现在在应用程序组件中,我已经包含了我的自定义类,如下所示:

    '用户' => [ 'identityClass' => 'app\models\Employee', 'enableSession' => 真, ],

  2. 我在Employee模型中实现了foll方法如下:

    公共静态函数 findIdentityByAccessToken($token, $type = null) { 抛出新的 NotSupportedException(); }

    公共函数 getId() { 返回 $this->EmpId; }

    公共函数 getAuthKey() { 抛出新的 NotSupportedException(); }

    公共函数 validateAuthKey($authKey) { 抛出新的 NotSupportedException(); }

    公共静态函数 findByUsername($username) { return self::findOne(['Username'=>$username]); }

    公共函数 validatePassword($password) { 返回 $this->密码 === $password; }

  3. 在 LoginForm 模型中,我有以下内容。 Insted 的用户,我已经包括 自定义类 Employee。

    公共函数 getUser() { if ($this->_user === false) { $this->_user = Employee::findByUsername($this->username); }

    return $this->_user;
    

    }

现在当我尝试登录并提供用户名和密码时,它给出了以下错误:

未知属性 – yii\base\UnknownPropertyException

获取未知属性:app\models\Employee::username

【问题讨论】:

    标签: yii2-basic-app yii2-user


    【解决方案1】:

    注意您的列名中的大小写 - 这应该与模型中的属性相同。 即:替换 - $this->usename to $this->用户名;

    【讨论】:

      猜你喜欢
      • 2012-10-04
      • 2015-02-25
      • 1970-01-01
      • 2012-04-29
      • 2012-03-18
      • 2011-07-05
      • 2013-12-02
      相关资源
      最近更新 更多