Symfony2 KnpMenuBundle:即使菜单项不在该菜单上,也将其设置为活动状态 [英] Symfony2 KnpMenuBundle: set active a menu item even when its not on that menu

查看:28
本文介绍了Symfony2 KnpMenuBundle:即使菜单项不在该菜单上,也将其设置为活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了我的菜单构建器并且它可以工作.我的路线之一是

I created my menu builder and it works. One of my route is

/database

但这有一个子路由:

database/view/{id}

我不想将视图路由放入菜单项中,因为没有 ID 它将无法工作.

I don't want to put the view route into the menu items because without the ID it won't work.

但我希望数据库路由在用户处于视图中时处于活动状态.

But I want the database route to be active when the user is on the view.

我该怎么做?

推荐答案

通过这个小技巧设法解决了:

Managed to solve it with this little hack:

在添加所有子项之后但在返回菜单之前我添加的 menuBuider 中

in the menuBuider after you add all the Children but before you return the menu i added

$request = $this->container->get('request');
        $routeName = $request->get('_route');
        switch ($routeName)
        {
            case 'battlemamono_database_view_by_name':
            case 'battlemamono_database_view_by_id':
                $database->setCurrent(true);
                break;
        }

这会检查路线并将所需的菜单设置为活动状态.

this checks the routes and sets the needed menu active.

这篇关于Symfony2 KnpMenuBundle:即使菜单项不在该菜单上,也将其设置为活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆