要登录yii,我想在数据库表(mysql)上执行此操作,而不是在UserIdentity类中提供的默认“admin”和“demo”默认值。问题是,我创建的数据库中的用户表不使用用户名和密码字段进行身份验证,而是使用电子邮件和密码字段。因此,当我在UserIdentity.php,LoginForm.php,SiteController.php,login.php中将所有“用户名”更改为“电子邮件”变量时,我收到错误:
未定义属性“UserIdentity.email”。
错误指向我在此处所做的更改,将用户名替换为电子邮件,如下所示:
public function authenticate()
{
$user = User::model()->findByAttributes(array(
'email' => $this->email
));
非常感谢您的帮助。
答案 0 :(得分:0)
您可以在登录UserIdentity时更改电子邮件。
$user = User::model()->findByAttributes(array(
'email' => $this->username
));
或添加新字段'电子邮件'到UserIdentity并使用它。