Rights For Menu

i have so many link in my top navigation, and i have 5 category of users,

now what is your advise to handle the menu (Navigation) for specifics user,

for example:

for admin Role show all

for Staff Role show x,y,z.


I’ll suggest you to implement a sort of Factory Pattern to build different menu for different role.

class MenuFactory


    public static function guestMenu() { /* ... */ }

    public static function adminMenu() { /* ... */ }

    public static function attendeeMenu() { /* ... */ }

    public static function speakerMenu() { /* ... */ }

    public static function someMenu() {

        return array(

            /* here you can return menu items for this specific role */




What’s wrong with the “visible” option of CMenu::items?

Instead of using visible, you can also dynamically build your menu, according to some factors (like user role, level or access right).

Here is my example:

if((isset(Yii::app()->user->level)) && (Yii::app()->user->level >= <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />)


    $userMenu = array('label'=>'User', 'url'=>'#', 'active'=>(Yii::app()->controller->id === 'user'), 'icon'=>'user', 'items'=>array


        array('label'=>'View', 'url'=>array('/user/index'), 'icon'=>'eye-open'),

        array('label'=>'Manage', 'url'=>array('/user/admin'), 'icon'=>'check'),

        array('label'=>'Add', 'url'=>array('/user/create'), 'icon'=>'plus-sign'),

        array('label'=>'Logout', 'url'=>array('/user/logout'), 'visible'=>!Yii::app()->user->isGuest, 'icon'=>'off')



else $userMenu = array('label'=>'Logout', 'url'=>array('/user/logout'), 'icon'=>'off');

and then:



    array('label'=>'Contact', 'url'=>array('/main/contact'), 'icon'=>'envelope'),



When user is at certain level (i.e. he or she is an admin), he see extended menu, with a sub-menu. If he is not (a normal user), he only sees "logout" option.

but how can i play with "Visible" for checking with auth tables?

Add some methods to your user model to check if they have access and use those when they are logged in. You should use the same methods in CController::accessRules.

I’m doing this exactly, as I wrote in this article. I have level stored in my users table, which is read from DB upon successful login and then, in the function that builds menu (example given above), I check what is the level of currently logged-in user and change menu structure according to this.

Read mentioned article for more details.

Thank you very much, i wrote simple function in component and passing the value in "Visible",

Thanks for your advise