How do I add more parameters to sfRequest object, on server side, before the request is processed?
I tried below code but it does not work.
$request->setParameter('formname[id]');
Many thanks in advance.
Adding parameters to sfRequest object is quite simple.
$request->setParameter('newParam', 'newParamValue');
//see your added param
var_dump($request->getParameter('newParam'));
The problem i think you may have faced is, with array parameters Supposed you want to add "id" to your parameter "formname".
$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);
This should do it.
You can access the public request
attribute from $request
and set or add parameters.
Example:
$request->request->set("p1", "v1");
$request->request->set("p2", "v2");
Or
$request->request->add(array("p1"=>"v1", "p2"=>"v2"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With