登录模型尝试登录用户而不是显示登录表单 [英] Login model attempt to login user instead of display login form

查看:20
本文介绍了登录模型尝试登录用户而不是显示登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将另一个项目的整个代码移植到我的新 Yii 1.1.12 项目中.它是原始的,一切正常.

I have ported entire code from another project to my new Yii 1.1.12 project. It original one, anything worked just fine.

在我的新项目中(虽然我在登录区域没有触及任何东西)任何显示登录表单的尝试(或要求用户登录的任何操作的请求)都以 Login 模型尝试结束实际登录用户.

In my new project (though I touched nothing in login area) any attempt to display login form (or request to any action, that requires user to be logged in) ends in Login model attempting to actually login user.

当我请求任何需要登录的操作时,Yii内部"将我重定向到我的主 site 控制器的 actionLogin.但是,不是呈现登录表单,而是出现了一个奇怪的异常:

When I request any action, that requires login, Yii "internals" redirect me to actionLogin of my main site controller. But, instead of login form being rendered, I'm getting a bit strange exception:

CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'login' in 'where clause'. The SQL statement executed was: SELECT * FROM `users` `t` WHERE LOWER(login)=? LIMIT 1

一些内部测试证明,我的 site 控制器中的 loginAction() 的第一行:

Some internal tests proven, that first line of my loginAction() in my site controller:

if(Yii::app()->user->isGuest)
{
    $model = new Login;
    ...
}

导致实际尝试​​登录用户.有没有人知道这里发生了什么?

causes actual attempt to login user. Has anyone got any idea, what is going on here?

我从来没有遇到过这样的情况,在我的任何 Yii 项目中,当 $_POST 为空时,Login 模型的创建实际上尝试登录用户(没有表单被渲染过,所以没有提交过 POST 数据)并且当用户代码不执行 $model->login() 时.

I have never run into situation, in any of my Yii projects, that creation of Login model actually attempts to login user, when $_POST is empty (no form was ever rendered, so no POST data was ever submitted) and when user code does not execute $model->login().

编辑:这是一个标准的 Yii 方法(虽然对我来说仍然很神秘),所以我问了 另一个问题.

Edit: This is a standard Yii method (though still mysterious to me), so I asked another question on this.

任何人都可以在这里提供帮助或建议,可能出了什么问题,或者我错过了什么?

推荐答案

既然我模型的 NameLogin,那么 login() 方法在其中定义,作为 PHP 的构造函数.

Since my model's Name is Login, then login() method defined in it, acts for PHP as constructor.

这与 Yii 无关,这是 PHP 的基本行为,从旧的、糟糕的 PHP4 继承而来,仅在命名空间类的情况下从 PHP 5.3.3 开始弃用.当类定义不使用命名空间时,这种行为(将构造函数定义为与类同名的函数)仍然有效.

This has nothing to do with Yii, this is a base PHP behavior, inherited from old, bad PHP4 and depracated as of PHP 5.3.3 only in case of namespaced classes. When class definition does not use namespace, this behavior (defining constructor as function named the same way as class) is still valid.

有关详细信息,请参阅此答案或参阅 PHP 手册.

See this answer for more details or refer to PHP manual.

这篇关于登录模型尝试登录用户而不是显示登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆