Log in/Log out

Hi all

As you can see, I am posting a new topic for each problem I face and that’s because I am very very VERY new to Yii and I am developing my first app.

I have a model name User with CRUD. In my data base I have 5 fields: User name, Password, Log in date time, Log out date time and role.

For now I want user’s Last log in/log out to be saved in their fields. I only need to save the last instance and I am NOT saving every log in/log out.

I also need to know which file I have to modify.

Thank you

We can’t take you by the hand, but together with the guide you should be able to solve this. Here’s the recipe:

  1. Create a custom WebUser class in components/ which extends from CWebUser

  2. Configure this as your ‘user’ component in your main.php

  3. Override afterLogin and afterLogout and write to DB whatever you want there

Thanks. Where do I have to define the WebUser class which is inherited from CWebUser?

Do I have to create a new file? In which folder?

and by the main.php, you mean the one in protected/config folder?

Sorry if all of these look obvious/ hilarious questions but I am very new to Yii.

Thank you

Yes, new file. Location already answered above (components/WebUser.php). Configuration is in config/main.php, yes.

Sorry, but i can not repeat the guide here. Please spend some time to read it and understand the basics first.