Login model attempt to login user instead of display login form

StackOverflow https://stackoverflow.com/questions/22148785

  •  19-10-2022
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top