如何在 Symfony2 控制器中获取请求类型(主/子)? [英] How to get request type (master/sub) in Symfony2 controller?

查看:31
本文介绍了如何在 Symfony2 控制器中获取请求类型(主/子)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器中是否有可能获取请求类型?怎么样?

Is there possible get request type in controller? How?

推荐答案

要检测请求是否是主请求,需要使用 RequestStack,它应该被注入到您的控制器中.请求栈有3个有用的方法

To detect if the request is a master or not requires the use of the RequestStack, which should be injected into your controller. The request stack has 3 useful methods

getCurrentRequest();
getMasterRequest();
getParentRequest();

如果当前请求是主请求,getParentRequest() 将始终返回 null.

The getParentRequest() will always return null if the current request is the master.

这篇关于如何在 Symfony2 控制器中获取请求类型(主/子)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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