Zend - 隐藏表单并显示消息
我有一个带有几个字段的 zend 表单。
当表单验证时,我想隐藏表单并显示成功消息。
有很多方法可以做到这一点 - 重定向到另一个控制器操作、渲染另一个视图脚本、在视图助手/会话中标记等等。
这有什么最佳实践吗?
谢谢。
I have a zend form with a few fields.
When the form validated I would like to hide the form and show a success message.
There are so many ways to do it - redirect to another controller action, render another view script, flag in the view helper/session and more.
Is there any best practice for this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为人们经常使用其他两个答案中发布的解决方案,该解决方案检查表单是否已发布且有效,然后将消息传递到视图。
我认为这种方法还可以,但不是最佳的。它将消息与工作流程紧密联系在一起,并产生了代码重复的需要。这是没有必要的。 IMO 消息传递应从工作流程中剔除,并使用可重用组件进行处理。恰好,Zend Framework 为我们提供了当时必要的工具——flashMessenger。
因此,我开始做的是向 flashMessenger 发送一条消息,每当我需要一条消息时,它将在下一次往返后自动显示,独立于表单操作,并且不需要额外的标记和 if 语句。
有关 flashMessenger 的示例和资源:
FlashMessenger 与通过这些链接找到的附加视图助手配合使用效果最佳!
I think quite often people use the solution posted in two other answers which checks if the form has been posted and is valid and then passes a message to the view.
I think the approach is ok but not optimal. It ties messages closely into the workflow and creates the need for code repetition. This is not necessary. IMO messaging should be taken out of the workflow and handled with a reusable component. As it happens, Zend Framework provides us with then necessary tool, the flashMessenger.
So, what I started doing is sending a message to the flashMessenger, whenever I need one, it will be shown after the next roundtrip automatically, independent of the form action and takes away the need for additional markup and if statements.
Examples and resources concerning the flashMessenger:
FlashMessenger works best with the additional view helper found via these links!
这是我的方式:
在控制器中,当表单提交成功时,我设置
并在视图文件中我只是问:
This is my way:
In controller,when the form was submitted as successfull,I set
and in view file I just ask:
我认为:
和
I think this:
and