0

我正在开发一个 Yii 项目,在菜单中,我想在访问特定项目时将菜单项设置为动态激活......我无法理解如何为静态页面执行此操作。这是我的代码:

 <?php $this->widget('zii.widgets.CMenu',array(
      'items'=>array(                   
           array('label'=>'Home', 'url'=>array('/site/index'),'active'=>(Yii::app()->controller->id=='site' && Yii::app()->controller->action->id=='index')),
           array('label'=>'About Us', 'url'=>array('/site/page', 'view'=>'about')), //HOW SHOULD I KNOW WHEN SHOULD THIS GET ACTIVE
           array('label'=>'News', 'url'=>array('/news/index'),'active'=>Yii::app()->controller->id=='news'),
           array('label'=>'Gallery', 'url'=>array('/images/index'), 'active'=>Yii::app()->controller->id=='images'),
           array('label'=>'Calendar', 'url'=>array('/calendar/index'), 'active'=>Yii::app()->controller->id=='calendar'),
           array('label'=>'Contact Us', 'url'=>array('/site/contact'), 'active'=>(Yii::app()->controller->id=='site' && Yii::app()->controller->action->id=='contact')),
        ),
 )); ?> 
4

1 回答 1

2

试试看:

array(
    'label' => 'About Us', 
    'url' => array('/site/page', 'view'=>'about'),
    'active' => Yii::app()->controller->id == 'site' && 
                Yii::app()->controller->action->id == 'page' && 
                Yii::app()->request->getParam('view') == 'about'
),
于 2012-11-12T12:09:45.693 回答