【发布时间】:2014-03-22 05:48:24
【问题描述】:
我正在尝试使用 Zend\Navigation 从视图助手中的模板创建菜单栏。
我离得更近了,并用我现在拥有的代码编辑了这个线程。
这里是视图助手:
<?php
namespace Helpdesk\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Navbar extends AbstractHelper implements ServiceLocatorAwareInterface {
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function __invoke() {
$partial = array('helpdesk/helpdesk/subNavTest.phtml','default');
$navigation = $this->getServiceLocator()->get('navigation');
$navigation->menu()->setPartial($partial);
return $navigation->menu()->render();
}
}
我在 module.config.php 中这样配置导航:
'view_helpers' => array(
'invokables' => array(
'navbar' => 'Helpdesk\View\Helper\Navbar',
),
),
'navigation' => array(
'default' => array(
array(
'label' => 'One',
'route' => 'link',
),
array(
'label' => 'Two',
'route' => 'link',
),
array(
'label' => 'Three',
'route' => 'link',
), ...
但是当我像 <?php echo $this->navbar(); ?> 这样在我的视图中显示它时,它只显示部分模板没有来自 module.config.php 的导航配置。
如果我在我的视图中正确执行以下操作,它会在我设置的配置中正常显示:
<?php $partial = array('helpdesk/helpdesk/subNavTest.phtml','default') ?>
<?php $this->navigation('navigation')->menu()->setPartial($partial) ?>
<?php echo $this->navigation('navigation')->menu()->render() ?>
为什么我的视图助手没有拉入导航配置?
【问题讨论】:
标签: dependency-injection zend-framework2