events, behaviors or what else

hello, every1.

what is the best way to update model’s field after user logged in. I.e. user enters login/password and after that ‘lastLogged’ field updated with NOW(), for example.

i puzzled with events and behaviors. Any ideas?

Hi Andrey,

Take a look at this:

If the link doesn’t work, Search in “Documentation” -> “The Yii CookBook” -> “How to add more information to Yii::app()->user”

If you want to store lastlogged onto database, inside authenticate() method you can instantiate a Model and execute a query through DAO:

$model = new USERMODEL; // UserModel Extends ActiRecord, I guess...

$model->ID = $userid;

try {

    $model->connection = Yii::app()->db;

}catch(PDOException $e){

    echo $e->getMessage();

    //throwexception ....



$sql = "UPDATE table SET lastlogged = NOW() WHERE USERID = '".$model->ID."'";




– Miguel.


i read that cookie. it’s about ‘property’ at app()->user. i wanna other thing.

Well, ur ‘auth’ method is ok, but not so flexible, it’s more like hardcore. i would like to do something in that way:

user logged in, event ‘loggedin’ raises, each ‘thing’ that knows how to handle it, catch and handle (in current situation - update field at DB, but someday, probably, i will need something other).

thanx, anyway :)

also i would like to use models, but not direct DAO :(

Hi again Andrey,

Perhaps you can override beforeValidate($scenario) and afterValidate($scenario) methods for your FormLogin, building your own ‘things’ ;). CFormModel extends from CModel. I didn’t test that possibility…

hmmm…will try to dig in that way. i still puzzled with events, after cookbooks too.