非 AJAX 网站上下文中的命令模式示例
我见过许多命令模式的示例
,但它们都倾向于在桌面应用程序的上下文中。
即“命令将调用该操作的对象与知道如何执行该操作的对象分离”
在纯 HTML(但由 Zend Framework MVC 驱动)网站的上下文中,我正在考虑用户“单击链接”,该链接应该刷新当前页面并调用某个命令。无论用户位于网站的哪个页面。
一个例子是,在博客应用程序中:
即
能够在
- “列表页面”(列出博客文章)
“编辑页面”上呈现 HTML 表单按钮,例如“删除博客文章” (编辑博客文章)
“列表页面”上的表单操作指向“列表页面”
- “编辑页面”上的表单操作指向“编辑页面”
我怀疑 ZF MVC 的控制器部分是一种命令模式。然而,它将 URL 路由到特定的控制器。我还尝试同时将命令操作路由到特定的命令接收器。
命令模式是否适用于此,还是仅在丰富的图形用户界面(例如桌面应用程序或支持 AJAX 的网站)的上下文中真正有用?
I have seen numerous examples of the Command pattern
But they all tend to be in the context of a desk-top application.
i.e "Command decouples the object that invokes the operation from the one that knows how to perform it"
In the context of a pure HTML (but Zend Framework MVC driven) website, I am thinking of a user 'clicking a link' which should refresh the current page and invoke a certain command. No matter which page of the site the user is on.
An example would be, in a blogging app:
i.e
To be able to present an HTML form button/s to, say, "Delete Blog Post" on both:
- 'List Page' (lists blog posts)
'Edit Page' (edits a blog post)
The form action on the 'List Page' points to 'List Page'
- The form action on the 'Edit Page' points to 'Edit Page'
I suspect the Controller part of the ZF MVC is kind-of a command pattern. However, that routes URLs to a particular controller. I am trying to ALSO route command actions to particular command receivers at the same time.
Does the command pattern apply here or is it only really useful in the context of rich graphical user interfaces - such as desk-top apps or AJAX-enabled sites?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说这并不适用于此,它使使用 ZF 的部分可以非常简单地实现的事情变得过于复杂。
为所有按钮甚至一个按钮创建一个对象对于 Web 应用程序来说似乎有点过头了?该按钮的存在应基于您的 ACL,例如用户是否有足够的权限来访问该按钮。当然,应该对按钮指向的 URL 执行相同的 ACL 检查。
I'd say that is does not apply here and that it over complicates something that can be achieved pretty simply using ZF's partials.
Creating an object for all buttons or even a button seems over kill for a web application? The presence of the button should be based on your ACL, eg does the user have sufficient permissions to have access to this button. The same ACL check should of course be done on the URL that the button points to.