Action View Helper in Zend - Work around?

后端 未结 4 2086
别跟我提以往
别跟我提以往 2020-12-16 18:49

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

相关标签:
4条回答
  • 2020-12-16 18:57

    I'm not entirely sure what your exact problem is, however you can disable the layout:

    $this->_helper->layout->disableLayout();
    

    Then the requested Action will just display it's view script, which you can load into the tab.

    Any authorisation code you have will function as normal and you can display the requested view script for the Action, or not depending on if they have access.

    0 讨论(0)
  • 2020-12-16 19:03

    If you're not generating the tab/tab panes from existing markup, and you're loading the content on demand, then you simply must check whether the user has permission to access the tab before displaying the tab itself, and again when attempting to load the tab's content.

    Checking whether the user has these access permissions should be an acceptable mode of operation and should not be expensive to perform.

    If these actions produce content that works in some standalone page, in addition to the tabs, then the Action view helper is the corrent way to proceed. Simply perform the same ACL (or other) check performed in the action when generating the tab.

    0 讨论(0)
  • 2020-12-16 19:07

    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.

    0 讨论(0)
  • 2020-12-16 19:22

    You can catch any access exceptions by using a try/catch block:

    try { // action throwing exceptions } catch (Exception $e) { // catch silently }
    
    0 讨论(0)
提交回复
热议问题