开发者

How to modify/add post parameters in symfony?

How do I add more parameters to sfRequest obj开发者_高级运维ect, 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"));


The above solution is not firendly to implement with multi-level array (with i18n for exemple).

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

No need to merge your brain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜