Revision: 47458
Updated Code
at June 9, 2011 00:45 by postNuKe
Updated Code
/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'));
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getParam('action'));
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
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"
Revision: 47457
Updated Code
at June 8, 2011 10:52 by postNuKe
Updated Code
/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->getControllerName());
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getActionName());
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
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"
Revision: 47456
Updated Code
at June 8, 2011 10:48 by postNuKe
Updated Code
/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->getControllerName());
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getActionName());
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
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"
Revision: 47455
Updated Code
at June 8, 2011 10:46 by postNuKe
Updated Code
/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);
//busca la pagina actual del navigation.xml y pone titulo a la pagina
$pages = $view->navigation()->findAllByController($request->getControllerName());
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getActionName());
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
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"
Revision: 47454
Updated Code
at June 8, 2011 10:45 by postNuKe
Updated Code
/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);
//busca la pagina actual del navigation.xml y pone titulo a la pagina
$pages = $view->navigation()->findAllByController($request->getControllerName());
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getActionName());
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
foreach ($pages as $page) {
if ($page->action == $action) {
return $page;
}
}
throw new Exception("Can't find page in navigation...");
}
}
Revision: 47453
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 8, 2011 10:44 by postNuKe
Initial Code
/configs/navigation.xml
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<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>
</configdata>
/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);
//busca la pagina actual del navigation.xml y pone titulo a la pagina
$pages = $view->navigation()->findAllByController($request->getControllerName());
if (count($pages) == 1) {
$navPage = current($pages);
} else {
$navPage = $this->_getCurrentPageFromController($pages, $request->getActionName());
}
$translate = Zend_Registry::get('Zend_Translate');
$view->headTitle()->prepend($translate->_($navPage->getTitle()));
}
protected function _getCurrentPageFromController(array $pages, $action) {
foreach ($pages as $page) {
if ($page->action == $action) {
return $page;
}
}
throw new Exception("Can't find page in navigation...");
}
}
Initial URL
Initial Description
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.
Initial Title
Zend Framework - Navigation set current page title with tag title on navigation.xml
Initial Tags
navigation
Initial Language
PHP