在 symfony3 中获取渲染子组件中的路由控制器/动作 [英] get route controllers/action within rendered subcomponent in symfony3

查看:25
本文介绍了在 symfony3 中获取渲染子组件中的路由控制器/动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 base.html.twig 中,我渲染了一个组件:

In my base.html.twig I render a component:

{% block header %}
    {{ render(controller("AppBundle:Application\\Header:header")) }}
{% endblock %}

有没有办法获取当前的路由动作/控制器?即浏览器中的当前网址?

Is there a way to get the current route action/controller? i.e. the current url in the browser?

当我做 var_dump($request->get('_route'));die;结果为空

When I do var_dump($request->get('_route'));die; it results in null

推荐答案

如果你想得到实际的路由,在你的控制器中你可以得到这样的主请求:

If you want get the actual route, in your controller you can get the master request like this:

$this->container->get('request_stack')->getMasterRequest()->get('_route');

这篇关于在 symfony3 中获取渲染子组件中的路由控制器/动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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