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.
我们正在使用Zend路由器,它似乎覆盖了表单发送的参数。到达控制器的唯一参数是来自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.
注意“formUrl”缺失,它只有路由器的参数。
2 个解决方案
#1
You can use the request-object in your controller to access your data.
您可以使用控制器中的请求对象来访问您的数据。
Fetch the request object: $request = $this->getRequest();
获取请求对象:$ request = $ this-> getRequest();
Retrieve POST data (if your form is submitted via POST): $post = $request->getPost();
检索POST数据(如果您的表单是通过POST提交的):$ post = $ request-> getPost();
Retrieve GET data (if your form is submitted via GET): $get = $request->getQuery();
检索GET数据(如果您的表单是通过GET提交的):$ get = $ request-> getQuery();
Retrieve parameter in the order user parameters set via setParam(), GET parameters and POST parameters: $params = $request->getParams();
通过setParam(),GET参数和POST参数设置用户参数的顺序检索参数:$ params = $ request-> getParams();
If you fetch your data with getParams() the params set by the router will override your POST data.
如果使用getParams()获取数据,路由器设置的参数将覆盖您的POST数据。
So if you only want to fetch the data from your form, use the getPost() or getQuery() method.
因此,如果您只想从表单中获取数据,请使用getPost()或getQuery()方法。
#2
Probably you are sending your form data as GET, and have configured Zend_Router to rewrite the url (without taking the other get parameters).
您可能正在将表单数据作为GET发送,并已配置Zend_Router来重写URL(不带其他get参数)。
In that case the solution is to send the form data with POST or change the routes in Zend_Router.
在这种情况下,解决方案是使用POST发送表单数据或更改Zend_Router中的路由。
Your code would help to determine what your exact problem is.
您的代码将有助于确定您的确切问题。
#1
You can use the request-object in your controller to access your data.
您可以使用控制器中的请求对象来访问您的数据。
Fetch the request object: $request = $this->getRequest();
获取请求对象:$ request = $ this-> getRequest();
Retrieve POST data (if your form is submitted via POST): $post = $request->getPost();
检索POST数据(如果您的表单是通过POST提交的):$ post = $ request-> getPost();
Retrieve GET data (if your form is submitted via GET): $get = $request->getQuery();
检索GET数据(如果您的表单是通过GET提交的):$ get = $ request-> getQuery();
Retrieve parameter in the order user parameters set via setParam(), GET parameters and POST parameters: $params = $request->getParams();
通过setParam(),GET参数和POST参数设置用户参数的顺序检索参数:$ params = $ request-> getParams();
If you fetch your data with getParams() the params set by the router will override your POST data.
如果使用getParams()获取数据,路由器设置的参数将覆盖您的POST数据。
So if you only want to fetch the data from your form, use the getPost() or getQuery() method.
因此,如果您只想从表单中获取数据,请使用getPost()或getQuery()方法。
#2
Probably you are sending your form data as GET, and have configured Zend_Router to rewrite the url (without taking the other get parameters).
您可能正在将表单数据作为GET发送,并已配置Zend_Router来重写URL(不带其他get参数)。
In that case the solution is to send the form data with POST or change the routes in Zend_Router.
在这种情况下,解决方案是使用POST发送表单数据或更改Zend_Router中的路由。
Your code would help to determine what your exact problem is.
您的代码将有助于确定您的确切问题。