I have an xml navigation system with article as an element. The breadcrumb works as far as my article page where i display the list of articles with their title (as a link) and a teaser paragraph. The page where i display the full article does not show any breadcrumb navigation.
I know i'm doing something wrong but since i am new to zend i can't figure out where.
I would be grateful if someone could point me towards the right direction.
The XML Navigation:
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<about>
<label>About</label>
<controller>index</controller>
<action>about</action>
</about>
<board>
<label>Executive Committee</label>
<controller>index</controller>
<action>committee</action>
</board>
<events>
<label>Events</label>
<controller>index</controller>
<action>events</action>
</events>
<member>
<label>CNFS Members</label>
<controller>index</controller>
<action>member</action>
</member>
<news>
<label>Blog</label>
<controller>blog</controller>
<action>index</action>
</news>
<contact>
<label>Contact</label>
<controller>index</controller>
<action>contact</action>
</contact>
</pages>
</home>
</nav>
</configdata>
This is the function in the bootstrap file for navigation.
<?php
protected function _initViewNavigation(){
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
?>
This is how i display the breadcrumbs in the view:
<?php echo 'Your are here: ' . $this->navigation()->breadcrumbs() ->setMinDepth(0)->setLinkLast(false)->setSeparator(" / ");?>
From your xml, i guess that your articles list is at /blog, and an single article at /blog/article/'articleId' or something similar.
Your "news" section in your navigation map defines an action, "index" but to display an article you use an other action, that's why this node isn't matched anymore.
I guess you would like the current article's title to show at the end of your breadcrumb, and to do that you must append a custom page as a child of the "news" node, and setting it as 'active' :
public function articleAction(){
//get your article
$article = ....
$page = new Zend_Navigation_Page_Mvc(array(
'label' => $article->getTitle(),
'controller' => 'blog',
'action' => 'article',
'params' => array(
'id' => $article->getId() // replace with the param name + value that you actually use in your url
)
)
);
$page->setActive(true);
$this->view->_helper->navigation()->getContainer()->findOneBy('controller','blog')->addPage($page);
I wrote this code by memory without testing, so if it doesn't work as expected just tell me, i'll test and update this answer