0

Zend framework Nesting controllers

I was wonder if it is possible to have nested controllers.

I have an application that has a page with left bar and right bar.


              | --TAB----TAB----TAB--
   MyGroups   |
              |

So I want to have one controller to be as a wrapper for entire page then have myGroups controller for left bar, and for right side, there are many tabs that would show based on some selections. So I want to have one controller for each tab.

This is a very big application and each of those tabs do lots of other things. So I want have separate controller/model/view/layout for each tab and also for left side's myGroups.

What is the best way to approach this. I appreciate if you give me some code structure too.

Thank you very much. Alex

user1322977
  • 141
  • 2
  • 9

2 Answers2

1

You could use the the Action view-helper in your layout for each or your left and right bars. But the downside to this is that you incur three full server calls (complete with bootstrap and dispatch cycle) to render a single page. I consider that to be a pretty significant downside, especially if each bar needs its own database connection.

An alternative approach is to use front-controller plugins for your left and right bars. Register them at bootstrap, give them a postDispatch() hook which accesses/generates whatever data they need and places that data into the layout/view. Then your layout renders the content without needing to know how it got there.

David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • Thanks David, your answer was very complete. I will try it. – user1322977 Apr 10 '12 at 05:09
  • Check out [this answer](http://stackoverflow.com/questions/10074671/how-do-i-pass-variables-to-a-layout-in-a-multiple-module-layout-zend-framework/10075151#10075151) for some more details of accessing layout/view in your plugins. – David Weinraub Apr 10 '12 at 07:10
  • And if it all works out for, don't forget to "accept" the answer by clicking the checkmark. See [FAQ](http://stackoverflow.com/faq). ;-) Welcome to SO! – David Weinraub Apr 10 '12 at 07:12
0

If you use the 'action view-helper' suggested by David, you could always ajax these in for better UX - therefore the user can read what has currently been loaded, while waiting for the rest of the page.

Eddie Jaoude
  • 1,698
  • 15
  • 23