Gottlieb Notschnabel Gottlieb Notschnabel - 1 year ago 62
PHP Question

How can I check if request was a POST or GET request in Symfony2

I just wondered if there is a very easy way (best: a simple

I can call) to determine whether the request is a
or a

According to the docs,

A Request object holds information about the client request. This
information can be accessed via several public properties:

  • request
    : equivalent of

  • query
    : equivalent of

But I won't be able to use
to check, because both are existing attributes in the Request class.

So I was wondering of Symfony offers something like the

// or isQuery() or isPost() or isRequest();

mentioned above?

Answer Source

If you want to do it in controller,


or in your model (service), inject or pass the Request object to your model first, then do the same like the above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download