Yii, Item In Menu Only Available For Admins

i want to make a menu to be only available for admins, for now i have this code and show you in the code what i want to change.


<?php

if(Yii::app()->user->name = 'admin') //for now i use this to be rendered only if the name of the user is admin, but i want to change it to be available for everyone who are admin.

{   

    $this->widget('bootstrap.widgets.TbNavBar',array(

        'brandLabel'=>TbHtml::b(Yii::app()->name),

        'color'=>TbHtml::NAVBAR_COLOR_INVERSE,

        'items'=>array(

            array(

                'class'=>'bootstrap.widgets.TbNav',

                'items'=>array(

                    array('label'=>'Home', 'url'=>array('/site/index')),

                    array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

                    array('label'=>'Contact', 'url'=>array('/site/contact')),

                    array('label'=>'Users', 'url'=>array('/user/index')),

                ),

            ),

            array(

                'class'=>'bootstrap.widgets.TbNav',

                'htmlOptions'=>array('class'=>'pull-right'),

                'items'=>array(

                    array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

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

                ),

            ),

        ),

    )); 

}

else

{

    $this->widget('bootstrap.widgets.TbNavBar',array(

        'brandLabel'=>TbHtml::b(Yii::app()->name),

        'color'=>TbHtml::NAVBAR_COLOR_INVERSE,

        'items'=>array(

            array(

                'class'=>'bootstrap.widgets.TbNav',

                'items'=>array(

                    array('label'=>'Home', 'url'=>array('/site/index')),

                    array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

                    array('label'=>'Contact', 'url'=>array('/site/contact')),

                ),

            ),

            array(

                'class'=>'bootstrap.widgets.TbNav',

                'htmlOptions'=>array('class'=>'pull-right'),

                'items'=>array(

                    array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

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

                ),

            ),

        ),

    ));

} 

?>

im using (if) for each widget if the condition returns true, but what i want to change is… the menu "user", to be only rendered for everyone thats admin, if not then not render and deny access.

Use CWebUser.checkAccess(), called as:




Yii::app()->user->checkAccess('ROLE_NAME')



Where ROLE_NAME is a role assigned to each user that is supposed to be an admin.

For more information please read the guide about authorization and authentication.