I am very new with zend and I want to build a navigational menu on some part of my site - let's say I have 20 pages but i just want to create a menu of 5 items and visible only for 4 pages. This might be a silly question but Is there a way to make it on my controller and not in bootstrap? I just really cant find an example for this :(
Perhaps a view helper? This way it can be called from the view script on the 4 pages that you want it to be shown on:
<?php
class Default_View_Helper_ShortNav extends Zend_View_Helper_Abstract
{
/**
* Generate a Zend_Navigation object
* @return Zend_Navigation
*/
public function shortNav()
{
//psudo code
$pages = array();
$model = new Default_Model_Pages();
$rows = $model->fetchAll();
foreach($rows as $page)
{
$pages[] = array(
'label' => $page->title,
'module' => 'default',
'controller' => 'index',
'action' => 'page',
'params' => array('page' => $page->slug),
'containerClass' => 'page',
);
}
$nav =new Zend_Navigation();
$nav->addPage(
array(
'label' => 'Pages',
'route' => 'index', //route name
'params' => array(), //route parameters
'pages' => $pages
)
);
return $nav;
}
}
In the view script:
<?php
$nav = $this->shortNav();
echo $this->navigation($nav);
In the view helper you will need to change the fetch all to select ONLY the pages you want, and in the view script you will need to wrap the echo in an if statement to show only on the pages you want it to show.
Hope this is useful.