I would like to use all properties of an object extracted from DB.
I have user table in the DB with multiple field. I know I can save each using setState() but is there any way I can use the whole object rather than having so many setState() functions?
That helps alot and it really helped but I ran into a new problem. It is not a problem itself but me code is "cheap"
In mu CMenu widget, I am trying to print the user’s firstName from the DB but once the user logs out, there would be no firstName to be print out.
I solved it by calling some function such as isLogedIn() from WebUser and have bunch of IF-ELSE statement it get check the user logging status and print the proper menu
That’s what does not look correct. At this point I am dealing just with two types of users: Logged In and not Logged In. Later on I may need to deal with other types of user.i.e. Logged in but his ID# starts with 2 OR
Logged in but department ID == 3 (I just made an example)
For each of these I may need to print different menus. Should I keep adding IF-THEN-ELSE statements over and over.
Thank you again for your short and well working answer.
I did play with visible and active but these two didnt work. I want to print firstName of whoever is logged in but when there is no user, there is no firstName neither and I think visible tries to "evaluate" Yii::app()->user->model->lastName but does not show it.
I though maybe active will do that but when user is logged out we dont have access even to Yii::app()->user…
Well why do you need if-else? It should be possible to use $this->widget(‘zii.widgets.CMenu’) once and work with ‘visible’ to make sure all the menu items show up for each of the relevant users.
Maybe you can show your whole menu code which includes if-else.
I think there would two potential problems with working with visible option:
If user knows the URL, s/he can jut type it.
We can solved the first problem with using isGuest from WebUser but the isGuest just tells us if there is a logged in user or not.
I may need to check more filed in my DB and give the user proper access. For example:
User with role== Manager and Department == Software can create/see the list of user.
User with role== President can create/see/update the list of user.// Regardless of the department
User with role== Secretary and Department == Management can only see the list of user.
…
…
General idea is to have a list of users and list of roles (President, Secretary, Admin,…) and list of tasks (Create, Read,Update,Delete,…)
Then we want to assign certain tasks to certain roles and maybe change it later. Let say for not President can perform Create and Read. Secretary can do Read and Update and so on so forth.
At this point for each combination of Role and Task we need a function OR an IF-THEN statements. The above tables (User,Role, Task), have many to many relations, too.
Let me know if I am not clear and thank you for all your helps.
P.S. I am also thinking to add more fields such as Color,language in the DB and then once the user is Logged in, we know who the user is and set the theme color and the color field or the language of the entire application to that of the DB(these two things just came to my mind and I may not use them for a little while )