-1

If there's a better way to structure this to achieve my goals your thoughts are welcome.

I have a CMS where users can edit pages (sidebars, headers etc) these are all done in the IndexController.

Some pages need their own controller, ContactController for example. However I'd like them to be equally customisable.

From IndexController::IndexAction can I run NewsletterController::IndexAction and get the view output in a string? I don't simply want to render the view file, I want to run what's in the Action too.

2 Answers2

1

What you are asking is technically possible (in ZF1) but it's generally not a good idea. There's a certain level of overhead involved in firing up a ZF action, so this isn't something you want to do multiple times to serve a single request. It also makes your application more difficult to debug. Google 'zend framework actionstack' for more discussion on this topic.

What are you trying to do can probably be solved with view helpers. For example if what you want from the NewsletterController::IndexAction is a newsletter subscribe form, then create a view helper that outputs this form instead. The form this view helper outputs can still submit to the NewsletterController, but what you get is much faster, cleaner and easier to test.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • What I want from the NewsletterController is the formatted list of Newsletters, this comes from the DB in the Action and is output in the View. example.com/newsletter gives the output I want, but I'd like it wrapped with the same wrappings IndexController::Index gives to DB-bound pages. I could copy (or move) the code into the IndexController but I'd rather keep it separate and tidy. – Mill Hill Automation Nov 19 '12 at 12:45
0

Noob way but: have you tried file_get_contents() or cURL while building your URL with Zend URL View Helper

banzsh
  • 540
  • 1
  • 4
  • 18
  • This is a bad idea for several reasons, but in particular: You're adding unnecessary load to your web server, adding an additional HTTP request to the building of your page (which will run synchronously and block the main request while it completes). – Tim Fountain Nov 16 '12 at 18:50
  • Agreed, I don't want to be creating all that extra load, I can render anything I want from other controllers but not call the Action - which does the DB reading bits. – Mill Hill Automation Nov 19 '12 at 12:47