Zend Layout displays some parts on each page.

I'm new to the Zend Framework, and I'm trying to figure out how they want to display things. I am creating a website and I have a menu that is dynamically created from the database. If I invoke the correct action, I see how menu.phtml looks right.

Now I would like this menu.phtml file to appear on every page, and I don't know how to do it. I read about placeholders, helpers ... but didn't seem to understand.

I assume that I need to call an action to create menu.phtml, make it and place it in placeholder, I can call from my layout.phtml, but I can’t see how I do it.

Thanks in advance.

DECISION:

In layout.phtml, I added the following line:

<?php echo $this->action('menu', 'page', null, array());?> 

This will access the menuAction in the PageController and start it. The variables will be populated, the required code will be executed before displaying the menu.phtml script view.

+4
source share
1 answer

You can do something like this:

Suppose you display a menu in some kind of div called a header.

 <div id='header'><?= $this->render('menu.phtml'); ?></div> 

You must add the correct path to access menu.phtml in the production controller.

 public function init() {    $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/'); } 

If you want to pass the values ​​to the menu.phtml file.

 <?php echo $this->partial('page/menu.phtml', array('var1'=>'value1','var2'=>'value2') ); ?> 
+4
source

All Articles