Reputation: 31560
I spent a little while trying to figure out how to implement a sub menu bar and eventually decided all I really want is a little helper method that appends my template to the current view instead of an actual view helper:
//To use in any action requiring the sub navbar to be displayed
protected function addSubNav(ViewModel $view) {
$subNavView = new ViewModel();
$subNavView->setTemplate('helpdesk/helpdesk/subNav');
$view->addChild($subNavView, 'subNav');
return $view;
}
But when I call it in a method like this $this->subNav in my template is null:
public function indexAction() {
//return new ViewModel();
$this->addSubNav(new ViewModel());
}
When doing $this->subNav in index.phtml is NULL, why is that?
addSubNav() should be returning the view which I appended a template to.
Upvotes: 0
Views: 50
Reputation: 884
You don't return your view model a the end of your action
public function indexAction() {
return $this->addSubNav(new ViewModel());
}
Upvotes: 2