Creating Dynamic Navbar

The tabs on my web app are dynamic depending on whether the user is logged in or not and what permissions they have.

For example, a guest user (not logged in) might see:

[color="#0000FF"][font="Verdana"]Home | Services | Login[/font][/color]

A logged-in, basic user might see:

[color="#0000FF"][font="Verdana"]Home | Tools | Upgrade | Logout[/font][/color]

And a logged-in, premium user might see:

[color="#0000FF"][font="Verdana"]Home | Tools | Premium Tools | Logout[/font][/color]

My question is where to put the code to set the tabs. I’ve considered:

  1. embed it directly in views/layouts/main.php the way the vanilla-Yii dynamically displays Login or Logout

  2. create a component that constructs the HTML and have main.php call the controller

  3. create separate files for each option and have main.php include the appropriate file (similar to how column1.php or column2.php get included)

  4. other ideas?

The PHP code is easy to do, but I’m still pretty new to Yii and want to follow Yii conventions.

Suggestions?

I think that the Yii convention is that you can do it in many ways.

One of the things I do here is to use "CDbAuthAssignment" (and what goes with it).

The visibility parameter then depends on whether the user has access to the operation/task or not.

You could even make your CMenu wrapper which checks the url the menu item points to in order to determine authorisation or not.

Using AuthAssignments allows you to define access rules in one place and use them in many (menu setup, action access control, …).

As I went through the list of Yii tips, I found this:

http://www.yiiframework.com/forum/index.php/topic/42529-authmanager-and-menu-visibility/

which explains in more detail what I suggested.

Thanks! The AuthManager info is helpful. My tabs are more complex than I originally described, but this will get me off to a good start.