I'm just starting out developing for Zend Framework 2. I'm trying to add a simple menu to my Application. The menu will eventually be loaded from a database as user-definable bookmarks, so at the moment, I am trying to instantiate a view helper I've defined, add pages programmatically in the controller, and then inject the view helper's navigation into the view model. My problem is that when I try to retrieve my view helper in the controller by using the ServiceLocator, I get a ServiceNotFoundException
:
Application\View\Helper\ShortcutsMenu:
namespace Application\View\Helper;
use Zend\Navigation\Navigation;
class ShortcutsMenu extends Navigation {
public function shortcutsMenu() {
//...
}
public function __construct() {
//...
}
}
and in Module.php
public function getServiceConfig() {
return array(
'view_helper' => array(
'factories' => array(
'shortcutsmenu' => function($sm) {
$smenu = new \Application\View\Helper\ShortcutsMenu();
return $smenu;
}
),
),
);
IndexController.php:
$smenu = $this->getServiceLocator()->get('shortcutsmenu'); // throws ServiceNotFoundException
//"Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for shortcutsmenu"
$smenu->addPage(AbstractPage::factory(array(
'label' => 'Homepage',
'order' => '-1',
'uri' => '/',
)));
// ...
}
Can anyone tell me what I'm missing?
Edit: The HTML I would like to generate in the application-wide layout would be something like:
<!-- Side tabs shortcuts -->
<ul id="shortcuts">
<li class="current"><a href="./" class="shortcut-home" title="Home">Home</a></li>
<li><a href="userpage1.html" title="My messages">My messages</a></li>
<li><a href="/a/b/c?id=4" title="Bob's calendar">Bob's calendar</a></li>
<li>...</li>
</ul>
probably using URI-style links rather than MVC ones.