/ Published in: PHP
                    
                                        
If you have Zend_Navigation in your application, you will use navigation.xml. This code set the page title ($this->view->headTitle()) with the current page title in navigation.xml.
$navigation->current() doesn't work in my opinion.
                $navigation->current() doesn't work in my opinion.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/configs/navigation.xml
<nav>
<home>
<title>Home</title>
<label>Home</label>
<module>admin</module>
<controller>index</controller>
<action>index</action>
</home>
<communities>
<title>Communities</title>
<label>Communities</label>
<module>admin</module>
<controller>communities</controller>
<action>index</action>
</communities>
</nav>
/library/App/Controller/Plugin/Navigation.php
class App_Controller_Plugin_Navigation extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
//$view = Zend_Registry::get('view');
$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
//search current page's title on navigation.xml by Controller Name
$pages = $view->navigation()->findAllByController($request->getParam('controller'));
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getParam('action'));
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
foreach ($pages as $page) {
if ($page->action == $action) {
return $page;
}
}
throw new Exception("Can't find page in navigation...");
}
}
/configs/application.ini
resources.frontController.plugins.Navigation = "App_Controller_Plugin_Navigation"
Comments
 Subscribe to comments
                    Subscribe to comments
                
                