Sending variables to the layout in Zend Framework

后端 未结 8 1535
[愿得一人]
[愿得一人] 2020-11-28 06:45

In my project I have a number of dynamic elements that are consistently on every page. I have put these in my layout.phtml

My question is: How can I send variables i

相关标签:
8条回答
  • 2020-11-28 07:42

    The standard view variables are available if you use the layout within the MVC. In bootstrap file, include this:

    Zend_Layout::startMvc();
    

    You must then tell each controller (or even each action, if you wanted granular control over several different layouts) which layout to use. I put mine in the init() of each controller. Here's an example, if your layout file is named layout.phtml:

    $this->_helper->layout->setLayout('layout');
    
    0 讨论(0)
  • 2020-11-28 07:42

    Well i guess you can have another solution by creating view helper.. create a file in application/views/helper and name it what ever you want abc.php then put the following code over there.

    class Zend_View_helper_abc {
    
        static public function abc() {
            $html = 'YOUR HTML';
            return $html;
        }
    }
    

    So you can use this helper in layout like..

    <?= $this->abc() ?>
    
    0 讨论(0)
提交回复
热议问题