Zend 中的动作视图助手 - 解决方法?
我正在构建一个界面,我想将其用作选项卡式浏览"功能.这些选项卡中的每一个都已编写为一个操作,选项卡式界面作为指向各个选项卡的链接工作正常.我决定尝试为这个控制器编写索引"页面 - 将所有选项卡的内容放入隐藏的 div 并使用 jQuery 在它们之间交换,但是一旦我开始使用动作视图助手 - 我遇到很多人说这是不好的做法.(见这篇文章)
其中一些操作会构建表单 - 从模型等中获取一些数据以进行显示.我希望每个操作都能继续独立运行(还有一些解析形式).
浏览到/item 应该会为您提供选项卡式菜单,以及隐藏标签中的所有 div 内容 - 其中/item/tab2 是特定操作(例如表单提交).
另一个复杂性/警告 - 如果用户无权访问该选项卡",某些操作将引发访问异常.我不想对系统进行两次访问检查(从而显示一个包含空内容的选项卡).
我只是想弄清楚处理这类事情的最佳实践是什么,我认为可能是操作助手.如果我尝试使用视图助手 - 我开始怀疑这是否是组装 Zend_Form 的正确位置.
有没有人对不使用 Zend_View_Helper_Action
的正确"方法有任何建议?
解决动作视图助手的正确方法,正如我在您引用的文章中所述,是创建可直接访问模型以获取数据的部分他们需要.如果这会在您的视图中涉及很多逻辑,则可以通过视图助手(您自己制作;)).
动作视图助手不仅受到性能问题的困扰,而且还会造成可怕的调试噩梦,如果您需要它,那么您的应用程序可能没有遵循 MVC,因此,您正在使用控制器进行重用,而不是模式,即模式意图.
您可以使用视图对象的渲染或部分方法从布局或当前操作视图中渲染部分.
如果您有多个操作来处理来自选项卡的多个可能的帖子,那么您应该将所有这些操作设置为呈现相同的视图脚本,然后该脚本将使用直接来自模型的数据呈现所有选项卡.>
I'm working on building up an interface that I want to function as a "tabbed browsing" sort of function. Each of these tabs has already been written as an action and the tabbed interface works fine as links to the individual tabs. I decided to try writing the "index" page for this controller - putting the content of all the tabs into hidden divs and swapping between them with jQuery, but once I started to use the action view helper - I ran into a lot of people saying that its bad practice. (see this article)
Some of these actions build up forms - grab some data from the model, etc to display. I want each of the actions to continue to function on their own (some parse forms as well).
Browsing to /item should give you the tabbed menu, plus all of the div's contents in a hidden tag - where /item/tab2 is a specific action (form submit for instance).
Another complication/caveat - Some of the actions will throw Access Exceptions if the user doesn't have access to that "tab". I'd prefer not to build access checking into the system twice (thus showing a tab with empty content).
I'm just trying to figure out what the best practice is to handle this sort of thing, and I thought that the action helper might be it. If I try to use View Helpers - I start wondering if that is the right place to assemble a Zend_Form.
Does anyone have any suggestions on the "proper" way to work around not using the Zend_View_Helper_Action
?
The Correct way to work around the action view helper, as I stated in the article you cited, is to create partials which access the model directly to fetch the data they need. This can be through a view helper (you make this yourself ;)) if this would involve a lot of logic in your view.
The action view helper is plagued with more than just performance issues, but also creates horrendous debugging nightmares, and if you need it, then your application is probably not following MVC, and therefore, you are using the controller for reuse, instead of the model, which is the patterns intention.
You can render partials from within your layout or current actions view with the render or partial methods of the view object.
If you have multiple actions to deal with multiple possible posts from your tabs, then you should set all of these actions to render the same view script, which will then render all of the tabs with data direct from the model.
相关文章