php - Zend Framework: Layout -


How can I add a variable to your layout.phtml? I can add it in every controller like here:

But that is not really evocative and bootstrap I do not want to add too

You can create called LayoutDefaults front controller plugin:

  class MyLib_Controller_Plugin_LayoutDefaults extends Zend_Controller_Plugin_Abstract {public function preDispatch (Zend_Controller_Request_Abstract $ Request ) {$ Mvc = Zend_Layout :: getMvcInstance (); If (! $ MVC) returns; $ View = $ MVC-> GetView (); If (! $ View) returns; / ** * Set default * / $ view- & gt; Value 1 = "default value 1"; }}  

In your front controller:

  Zend_Controller_Front :: getInstance () - & gt; registerPlugin (New MyLib_Controller_Plugin_LayoutDefaults ());  

In your layout.phtml?

  & lt; = $ This- & gt; Escape ($ this-> Values1) & gt;  

And finally, in your controllers, as needed default override:

  $ this- & gt; View-> Value1 = "new value1";  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -