2

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().

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

Can anyone help here or advice, what could be wrong, or what am I missing?

Community
  • 1
  • 1
trejder
  • 17,148
  • 27
  • 124
  • 216
  • ok, you have ported entire code from another project that might has changed the flow of the app.Can you post the site controller login action? – Rafay Zia Mir Mar 03 '14 at 14:44
  • @RafayZiaMir The code you have above, in second code example, actually **is** part of my controller and its `actionLogin()` action, as I explained above it. Both actions in both projects (original and ported one) contains _exactly the same code, as in every auto generated Yii app and hasn't been changed ever since generation_. Beside presented code, there is only standard AJAX reply (`if(isset($_POST['ajax'])`), standard login form processing (`$model->validate() && $model->login()`) and login form render. Nothing unusual, everything generated. Only flow / processing is strange. – trejder Mar 04 '14 at 07:03
  • This problem is narrowed to question: _Why `Login::login()` method is fired upon `Login` model creation_? What is the reason or logic behind an attempt to login user, if you have nothing to log in (no username and password, `$_POST` is empty, no data submitted as no form was even rendered). So, this is a side-problem, easily solve, by adding `login` column to database or rewriting `login()` and `authenticate()` methods (as planned). But, the question remains open: _why Yii attempts to login user upon login model creation_? More at [Yii forum](http://bit.ly/1i1UtjW). – trejder Mar 04 '14 at 08:06
  • You need to show us more code. Especially the controller where you call the login method if the post is set. – Carl Boisvert Mar 04 '14 at 02:35

1 Answers1

0

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

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.

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

Community
  • 1
  • 1
trejder
  • 17,148
  • 27
  • 124
  • 216