We are using the Zend Router and it seems that its overwriting the parameters that are sent by forms. The only parameters that arrive to the controller are the params from the Url.
Does anyone know why this is happening?
Here is the config file:
; Routing config
routes.groups.route = groups/:group/:type/:idPost/:postUrl/:page
routes.groups.defaults.controller = groups
routes.groups.defaults.action = index
routes.groups.defaults.type = main
routes.groups.defaults.idPost =
routes.groups.defaults.postUrl =
routes.groups.defaults.page = 1
And the form:
<form action="<?= $this->_view->baseUrl ?>/groups/<?= $group['groupUrl'] ?>/deletepost/" method="post">
<input type="hidden" name="formUrl" value="<?=$formUrl ?> />
...
</form>
Controller:
public function deletepostAction() {
$params = $this->getRequest()->getParams();
print_r($params);
die;
}
…that outputs:
Array
(
[group] => dandy-handwriting
[type] => deletepost
[idPost] =>
[controller] => groups
[action] => index
[postUrl] =>
[idGroup] => 1
[lang] => en
)
note that “formUrl” is missing, its only the parameters from the router.
You can use the request-object in your controller to access your data.
Fetch the request object:
$request = $this->getRequest();
Retrieve POST data (if your form is submitted via POST):
$post = $request->getPost();
Retrieve GET data (if your form is submitted via GET):
$get = $request->getQuery();
Retrieve parameter in the order user parameters set via setParam(), GET parameters and POST parameters:
$params = $request->getParams();
If you fetch your data with getParams() the params set by the router will override your POST data.
So if you only want to fetch the data from your form, use the getPost() or getQuery() method.