How to change / add message options in symfony?

How to add additional parameters to the server side sfRequest object before processing the request?

I tried the code below, but it does not work.

$request->setParameter('formname[id]');

Thank you very much in advance.

+3
source share
3 answers

Adding parameters to the sfRequest object is pretty simple.

$request->setParameter('newParam', 'newParamValue');
//see your added param
var_dump($request->getParameter('newParam')); 

The problem that I think you might have encountered is with array parameters. Suppose you want to add "id" to your "formname" parameter.

$newParams = array('id'=>1);

//Merge the existing values in formname with your new value
$formnameArray = $request->getParameter('formname');
$mergedArray = array_merge($formnameArray, $newParams);

//save it back in the request obj
$request->setParameter('formname', $mergedArray);

That should do it.

+15
source

You can access the public attribute requestfrom $requestand set or add parameters. Example:

$request->request->set("p1", "v1");
$request->request->set("p2", "v2");

Or

$request->request->add(array("p1"=>"v1", "p2"=>"v2"));
+1
source

(, i18n).

//get the array
$formnameArray = $request->getParameter('formname');
//alter the array
$formnameArray['id'] = $newID;
$request->setParameter('formname', $formnameArray);

.

0

Source: https://habr.com/ru/post/1760706/


All Articles