I have ported entire code from another project to my new Yii 1.1.12 project. It original one, anything worked just fine.
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.
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
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?
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().
Can anyone help here or advice, what could be wrong, or what am I missing?
Your point is correct (about the source of a SQL error), but the thing is, why there is any SQL fired at all and why a login process takes place in this scenario?
I have checked, that this happens also in all my other projects, but since everything is OK there, with the database, there is no visual proof of what is happening.
This problem is now narrowed to the question: Why Login::login() method is being fired upon Login model creation? What is the reason or logic behind an attempt to login user, if you have actually nothing to log him or her in (no username and password, $_POST is empty, no data has been submitted as no form was even rendered, so user hasn’t even got chance to enter and submit anything).
This turned out to be a side-problem, easily solve, by adding login column to database or completely rewriting login() and authenticate() method (as it was planned). But, the question remains open: why Yii attempts to login user upon login model creation?
This has become off-topic, as this has nothing to do with my own project (or any other module-only application). This is a standard Yii issue (though still mysterious to me), so I started another question for this purpose. Please, answer there, if you have something to say about this. Thanks!