如何在Yii2菜单小部件中突出显示文本

时间:2018-02-20 07:32:56

标签: php menu yii2

我在yii2中使用菜单小部件来创建侧边菜单。 我的菜单包含两个指向相同操作的菜单项。一个链接用于参数,另一个链接用于没有参数。 但是,当我点击任何仅链接链接而没有参数高亮显示时。单击时如何突出显示其他链接? 我生成菜单的代码是:

dmstr\widgets\Menu::widget(
            [
                'options' => ['class' => 'sidebar-menu'],
                'items' => [

                    [
                        'label' => 'Leave',
                        'icon' => 'share',
                        'url' => '#',
                        'visible'=>  (General::ifUserPermitted('leaveCreate')||General::ifUserPermitted('leaveDeleteOwn')||General::ifUserPermitted('leaveReject')||General::ifUserPermitted('leaveSeeAllLeave')||General::ifUserPermitted('leaveTeamLeaveApproval')||General::ifUserPermitted('leaveViewOwn')), 
                        'items' => [
                            [
                                'label' => 'Create',
                                'icon' => 'creative-commons',
                                'url' => ['/leaveparent/create'],
                                'visible'=> General::ifUserPermitted('leaveCreate')
                            ],
                            [
                                'label' => 'View',
                                'icon' => 'address-book-o ',
                                'url' => ['/leaveparent/index', 'LeaveparentSearch[userName]' => common\models\Person::getFirstNameByUserId(Yii::$app->user->id)],
                                'visible'=> General::ifUserPermitted('leaveViewOwn')
                            ],
                            [
                                'label' => 'View All',
                                'icon' => 'address-book-o ',
                                'url' => ['/leaveparent/index'],
                                'visible'=> General::ifUserPermitted('leaveSeeAllLeave')
                            ],
                            [
                                'label' => 'Pending for approval',
                                'icon' => 'check',
                                'url' => ['/leaveparent/index', 'LeaveparentSearch[report_to_user_id]' => Yii::$app->user->id, 'LeaveparentSearch[status]' => 'Pending'],
                                'visible'=> (General::ifUserPermitted('leaveTeamLeaveApproval')||General::ifUserPermitted('leaveReject'))
                            ],
                        ],
                    ],
                ]
            ]
)

1 个答案:

答案 0 :(得分:0)

在要设置为活动的项目配置中添加active配置密钥。当条件满足时,它应该返回true。类似的东西:

'active' => Yii::$app->controller->id === 'leaveparent' 
                && Yii::$app->controller->action->id === 'index',