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