Where should I put the code of validated user information ?

Hi all, I am new to Yii, and now developing a new web apps with Yii.

My question is, after validate user login,


if($form->validate()) {

	# Store this logined user information

	Yii::app()->user->setId(81); # Id should get from DB

	Yii::app()->user->setName("blablabla"); # Name should get from DB



Both 2 lines should I put? I mean should I put under

  1. UserIdentity.php component, directly add this 2 lines after SQL validation (inside authenticate function)

  2. Under this controller/action, if this case, need to query the DB again for the Id/Name.

I understand we should keep a component as modular as possible, if I use the first option, then UserIdentity component is doing additional job other then only perform authentication, which is not modular enough.

If I use the second approach, then need to perform additional db jobs, wasting resources.

Can anybody advice? Or is there any other methods?

Thanks in advance.

This is UserIdentity's work

In fact the default one already saves the name like the id, you should change it to save the id and the username.

Your exact case is explained in the blog tutorial, try this:


Thanks Jack!!  ;)