zend layout - PHP: Zend_Layout: Where to write business logic? -


On most projects, I use multiple layout scripts.

Sometimes I need some data in my layout, instead of the page-specific layout-specific though the layout is used, the ISS is page-specific.

Therefore the bootstrap or the action constructor will be good locations for selection of layouts. But IMHO would be a good place to inject the not data, expect a special layout.

I can think that there is only some other business logic in the layout idea sheet in place. Although there is something that I want to do :)

Where do you write your layout-specific business logic?

- UPDATE :

Layout-specific business logic can occur;

  • Currently logged in user's username
  • Number of new messages in the user's message Inbox
  • Random "Did you know ..? ? " Tip

This type of content is best done with ViewHelper

< Pre> class ViewHelper_RandomTip {public function randomTip () {$ tip = TipsModel :: getRandom (); Return "

Random Tip

$ Tip & lt; / div & gt; ; "); } // ...}

Then in your layout, use it with

  $ echo-> randomTip ();  

Note that this is a code that is not run anywhere. How exactly do you use your model from the assistant and how do you return the content, you are completely dependent on you, you must also get the sense of registering ViewHelpers with Layouts.

  • More people will be telling you, you can not use this view from the model (which is wrong)

    Please also look at these related questions:

And take a look at what kind of work does.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -