Zend View Navigation Helpers. Solving typical problems. Suppose you want to display the following navigation elements. Main menu Submenu of main menu Breadcrumbs
Solution for main menu clear. <?= $this->navigation()->menu()->setMaxDepth(0) ?> Possible solution for submenu of main menu could be so. <?= $this->navigation()->menu()->setMaxDepth(1)->SetMinDepth(1)->setOnlyActiveBranch(true) ?> Now a few of the breadcrumbs. Suppose that we want to see breadcrumbs of the next request /catalog/products/view/id/1 as Catalog > Categories -> Product category > Product 1 As retreat. We don't declare '/catalog/products' in application.ini as page. And we don't want display breadcrumbs as 'Catalog > Products > Product 1' And we don't want display '/catalog/products' in submenu. Since '/catalog/products' is minor. '/catalog/products/index' simple redirects to '/catalog/categories'. Possible solution. class Catalog_ProductsController extends Zend_Controller_Action public function init() { $this->navigation = $this->_helper->getHelper('Navigation'); } public function viewAction() { $product = ... // find product // Navigation $this->navigation->addTo('id', 'catalog-categories', 'm', array( 'id' => 'catalog-categories-view', 'label' => $product['category_name'], 'controller' => 'categories', 'action' => 'view', 'params' => array('id' => $product['category_id']))); $this->navigation->addTo('id', 'catalog-categories-view', 'mcap', array( 'id' => 'catalog-products-view', 'label' => $product['name'])); And finaly little helper code. <?php class My_Controller_Action_Helper_Navigation extends Zend_Controller_Action_Helper_Abstract { protected $_container; public function __construct() { if (Zend_Registry::isRegistered('Zend_Navigation')) { $navigation = Zend_Registry::get('Zend_Navigation'); if ($navigation instanceof Zend_Navigation_Container) { $this->_container = $navigation; } } } public function addTo($property, $value, $fillFlags, $options) { if(null == $this->_container) { return; } if(!$page = $this->_container->findOneBy($property, $value)) { return; } $flags = str_split(strtolower(strval($fillFlags))); foreach($flags as $flag) { $request = $this->getFrontController()->getRequest(); switch($flag) { case 'a': $options['action'] = $request->getActionName(); break; case 'c': $options['controller'] = $request->getControllerName(); break; case 'm': $options['module'] = $request->getModuleName(); break; case 'p': $options['params'] = $request->getParams(); break; } } $page->AddPage(Zend_Navigation_Page::factory($options)); } public function direct($property, $value, $flags, $options) { $this->addTo($property, $value, $flags, $options); } } -- View this message in context: http://n4.nabble.com/Zend-View-Navigation-Helpers-Solving-typical-problems-tp931602p931602.html Sent from the Zend Framework mailing list archive at Nabble.com.