Is there possible get request type in controller? How?
相关问题
- Symfony2 Set Controller in the kernelControllerEve
- Webpack Encore: cannot import local dependencies
- Render custom attribute KNP Menu
- Problems with cap deploy a symfony2 project, can
- Allow CORS on symfony 4
相关文章
- Symfony : Doctrine data fixture : how to handle la
- Symfony is linked to the wrong PHP version
- Symfony2: check whether session exists or not
- Is there a way to modify the entity mapping config
- symfony2 form choice and mongodb
- Symfony 3.1 and OneUpUploaderBundle + Blueimp = Up
- Symfony does not remove entity from collection
- Symfony: Inject object (not service) to service co
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 methodsThe
getParentRequest()
will always return null if the current request is the master.Easy, just call the
getMethod()
method on yourRequest
object:This will return the HTTP method of the current request, e.g.
GET
,POST
,PUT
orDELETE
.I was looking for this myself, and it seems it is just passed around, so there doesn't seem to be one single place that knows what it is.
My thought for solving this would be to create a simple kernel.request listener that just adds an attribute to the request. Rough (un-tested) code below:
Then in the controller you should be able to do:
Again this is untested. You would need to write out the full listener class and add it to the services config file, but other than that I think this will work.