問題描述
我正在構建一個界面,我想將其用作選項卡式瀏覽"功能.這些選項卡中的每一個都已編寫為一個操作,選項卡式界面作為指向各個選項卡的鏈接工作正常.我決定嘗試為這個控制器編寫索引"頁面 - 將所有選項卡的內容放入隱藏的 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.
這篇關于Zend 中的動作視圖助手 - 解決方法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!