Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify/add post parameters in symfony?

Tags:

symfony1

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.

like image 384
LionHeart Avatar asked Dec 02 '22 04:12

LionHeart


2 Answers

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.

like image 117
Sheldon Fernandes Avatar answered Feb 17 '23 05:02

Sheldon Fernandes


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"));
like image 31
Amadu Bah Avatar answered Feb 17 '23 05:02

Amadu Bah