如何让普通表单的操作遵循 zend 自定义路由?
我已经选择了 zend 框架并正在使用它,这是我想要的情况 实现。
我有 default
和 user
modules
,用户有不同的布局 user_layout
,我在 predispatch< 中加载用户模块的
NovelsController
的 /code>。i 在 user_layout 中有一个小表单,其中 post
日期(从 到 )为 NovelsController 的 showAction。
代码
<!-- the form inside user_layout -->
<form method="get" action="/user/novels/show">
<table class="font">
<tr>
<td> <label for="to">From:</label></td>
<td class="simple_margin_left"><input type="text" id="from" name="from" size="12"/></td>
</tr>
<tr>
<td> <label for="to">To:</label></td>
<td class="simple_margin_left"><input type="text" id="to" name="to" size="12" /></td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center"><button type="submit" style="padding-left:10px; padding-right:10px; margin-left:0px" class="classy">Check</button> </td>
</tr>
</table>
</form>
这是我使用以下
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getPost());
到目前为止一切正常我现在想要启用对 show.phtml 的分页。所以我更改表单操作以在我的 application.ini 中获取和定义路线,那么
resources.router.routes.user-show.route = /user/novels/show/:page/:from/:to
resources.router.routes.user-show.defaults.controller = novels
resources.router.routes.user-show.defaults.module = user
resources.router.routes.user-show.defaults.action = show
resources.router.routes.user-show.defaults.page = 1
resources.router.routes.user-show.defaults.from = ""
resources.router.routes.user-show.defaults.to = ""
我如何制作表单操作遵循该规则,因为到目前为止它只是一个带有问号和变量=值的普通查询字符串。
我怎样才能做到这一点?感谢您阅读本文。
i've picked up zend framework and being playing with it, and here is a situation i'll like to
achieve.
i have default
and user
modules
, user has a different layout user_layout
that i load in predispatch
of NovelsController
of user modules.i have a small form in the user_layout that post
dates (from and to ) to showAction of NovelsController.
here is the code
<!-- the form inside user_layout -->
<form method="get" action="/user/novels/show">
<table class="font">
<tr>
<td> <label for="to">From:</label></td>
<td class="simple_margin_left"><input type="text" id="from" name="from" size="12"/></td>
</tr>
<tr>
<td> <label for="to">To:</label></td>
<td class="simple_margin_left"><input type="text" id="to" name="to" size="12" /></td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center"><button type="submit" style="padding-left:10px; padding-right:10px; margin-left:0px" class="classy">Check</button> </td>
</tr>
</table>
</form>
I use the following to
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getPost());
So far everything works fine i now want to enable pagination to the show.phtml.so i change the form action to get and defined route in my application.ini like so
resources.router.routes.user-show.route = /user/novels/show/:page/:from/:to
resources.router.routes.user-show.defaults.controller = novels
resources.router.routes.user-show.defaults.module = user
resources.router.routes.user-show.defaults.action = show
resources.router.routes.user-show.defaults.page = 1
resources.router.routes.user-show.defaults.from = ""
resources.router.routes.user-show.defaults.to = ""
how can i make the form action follow that rule, because up to now it's just a normal query string with question mark and variable=value.
How can i achieve that?thanks for reading this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于浏览器的工作方式,ZF 无法完成此操作(并且不值得这样做)。
当以任何语言提交 GET 表单时,浏览器都会将查询字符串构建为键值对并将其附加到操作中指定的 URL。
如果您坚持所有 url 都“漂亮”,您有几个选择:
This can't be done with ZF (and isn't worth doing) because of the way the browser works.
When a GET form is submit, in any language, the browser will build the query string as key-value pairs and append it to the URL specified in the action.
If you insist on all urls being 'pretty' you have a few options: