I wanted to set up the menu in layout.phtml using a dynamic call to the database.
I created a directory in library called plugins.
I put this in application.ini
autoloaderNamespaces[] = “Plugins”
I created a class in the plugins directory called Plugins_Layout with the file name Layout.php
I then added this to Bootstrap.php
I was then able to create the dynamic menu in layout.phtml
All was working as I expected.
I created a directory in library called plugins.
I put this in application.ini
autoloaderNamespaces[] = “Plugins”
I created a class in the plugins directory called Plugins_Layout with the file name Layout.php
- class Plugins_Layout extends Zend_Controller_Plugin_Abstract
- {
- public function preDispatch(Zend_Controller_Request_Abstract $request)
- {
- $layout = Zend_Layout::getMvcInstance();
- $view = $layout->getView();
- $content_mapper = new Application_Model_ContentMapper();
- $view->menu = $content_mapper->getMenu();
- }
- }
- protected function _initRoutes() {
- ......
- Zend_Controller_Front::getInstance()->registerPlugin(new Plugins_Layout());
- }
- <!--?php foreach($this--->menu as $url => $title) { ?>
- a href="/<?php echo $url ?>"><!--?php echo $title; ?--></a>
- <!--? } ?-->
Nguồn : http://blog.saunderswebsolutions.com