CakePHP - 你能让表单提交参数作为命名参数吗?
所以 GET 表单会创建通常的 url,例如
.../search/?q=apple
Can you make a form create urls like
.../search/q:apple/
So GET forms make the usual urls like
.../search/?q=apple
Can you make a form create urls like
.../search/q:apple/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢,伙计们。我找到了不同的解决方案。我只是将表单作为 POST 提交,在控制器的操作中,我读取帖子数据并使用名为 params 的帖子数据创建一个 url,然后 $this->redirect('...');到它。
Thanks, guys. I've found a different solution. I just submit the form as a POST and in the controller's action I read the post data and create a url with the post data as named params and then $this->redirect('...'); to it.
创建这些 URL 的方法可以在这里找到: http://book.cakephp.org/view /842/网址
The methods to create these URL's can be found here: http://book.cakephp.org/view/842/url
如果我理解正确的话,您本身并不是要创建不同的 URI,而是要以不同的方式序列化表单数据。换句话说,您感兴趣的是修改查询字符串而不是 URI 本身。
据我所知,这就是表单序列化数据的方式,并且没有办法真正覆盖这种行为。如果您确实想这样做,我怀疑您必须捕获提交事件,手动将表单数据序列化为您想要的格式,将该格式附加到表单的
action
值中,进行自定义向页面发出请求(通过location.href
等)并返回false
,以便表单本身永远不会真正被提交。当然,您也可以通过 Ajax 提交,这样您有更多的控制权。
我不知道有任何其他方法可以完成我认为您所要求的事情。
If I understand you correctly, you're not looking to create a different URI, per se, but rather to serialize the form data in a different way. In other words, you're interested in modifying the query string rather than the URI itself.
As far as I know, that's the way that forms serialize their data and there's no way to truly override this behavior. If you really want to do this, I suspect you'll have to capture the submit event, manually serialize the form data into the format you want, append that format to the form's
action
value, make a custom request to the page (vialocation.href
, etc.) and returnfalse
so that the form itself never actually gets submitted.Of course, you could also submit via Ajax where you have a little more control.
I'm not aware of any other way to do what I think you're asking.