Flex Menus Based on Login Username???

I’m just beginning to develop with Yii, and before I get too deep into the RBAC/database user table stuff, I just want to dynamically display and flex certain menu items based on the default (e.g. demo, admin) usernames for the starter application.

So basically, I found I need to set the ‘visible’ property of each menu item (e.g. in main.php and other files where menus are used) to see whether it should be visible depending on the username. To be able to set this appropriately (probably in the login authenticate method) for all menus in the application it would seem to mean that I need something “global” like Yii::app() but I don’t think I want to subclass that and add a property???

Is there some other (or existing) way to have every menu throughout the application have access to the username (or proxy, e.g. isAdmin, isDemo) of the current user in order to set the visible property for the menu item?

Thanks.

What I do:

For public vs. auth I check Yii::App()->isGuest

For auth user vs. admin I have a function that checks if user is admin and returns true/false based on outcome. Visible property thus is set. In my case I have a simple isAdmin flag in my user table for the time being until I get around to learning (or needing??) RBAC.

Uh, in the end, this was trivial. CWebUser tracks the username so you can just add the following to the form item array to display (or not) a menu depending on username.


'visible'=>Yii::app()->user->name == 'admin'