Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add request parameter to request

Tags:

symfony

I need to put a flag in an kernel.event_listener at stage kernel.controller in order to do something in an kernel.response-listener.

I thought about adding a parameter to the $request object, however have not found any method or this:

http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html

What is the best practice to pass some informatino from an kernel.controller-listener to an kernel.response-listener?

Use-case:

  • We want to set a cookie based on a validation of a specific request attribute (must be in kernel.controller-stage, since based on the result of the validation, the view may behave different).
  • The cookie can only be set in the kernel.response-listener, since it has the Response-instance.
like image 307
Chris Avatar asked Feb 20 '12 11:02

Chris


People also ask

How do you add parameters in GET request?

To do http get request with parameters in Angular, we can make use of params options argument in HttpClient. get() method. Using the params property we can pass parameters to the HTTP get request. Either we can pass HttpParams or an object which contains key value pairs of parameters.

How do you pass parameters in Python requests?

To send parameters in URL, write all parameter key:value pairs to a dictionary and send them as params argument to any of the GET, POST, PUT, HEAD, DELETE or OPTIONS request. then https://somewebsite.com/?param1=value1&param2=value2 would be our final url.

Can we send parameters in POST request?

In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

What are request GET parameters?

GET parameters (also called URL parameters or query strings) are used when a client, such as a browser, requests a particular resource from a web server using the HTTP protocol. These parameters are usually name-value pairs, separated by an equals sign = . They can be used for a variety of things, as explained below.


1 Answers

You can use $request->attributes to pass around information. In your controller listener:

$request->attributes->set('mykey', 'myvalue'); 

In your response listener:

$myvalue = $request->attributes->get('mykey'); 
like image 198
Bártfai Tamás Avatar answered Sep 25 '22 01:09

Bártfai Tamás