Symfony2 服务参数 - 传递当前请求 [英] Symfony2 service parameters - passing the current request

查看:59
本文介绍了Symfony2 服务参数 - 传递当前请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Symfony2 中创建一个服务,它将接收构造函数上的当前请求,并使用它来确定用于请求的浏览器类型.

I want to create a service in Symfony2 that will take in the current request on the constructor and use it to determine the type of browser used for the request.

我可以创建类并将其定义为服务,但如何使用 XML 服务定义传入当前请求?

I can create the class and define it as a service but how do I pass in the current request using the XML service definition?

推荐答案

您应该能够只使用 request 服务.但是,这需要使用 scope="request" 声明您的服务.我使用的另一种方法是注入服务容器并在需要时在那里检索 request-Service 表单.

You should be able to just use the request service. This however requires your service to be declared with scope="request". Another approach i used was to inject the service-container and retrieve the request-Service form there when you need it.

这篇关于Symfony2 服务参数 - 传递当前请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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