【发布时间】:2015-11-03 23:12:34
【问题描述】:
在我的项目中,我有一个导航,它是使用默认工厂从 config.php 文件中的数组创建的。我想将子页面添加到控制器中的当前页面。
class IndexController extends AbstractActionController {
public function newpageAction() {
$navigation = $this->getServiceLocator()->get('navigation');
$currentPage = $navigation->findById('index');
$options = array(
'id' => 'newpage',
'label' => 'New Page',
'route' => 'my-route',
'controller' => 'index',
'action' => 'newpage',
'active' => true,
);
$newpage = new \Zend\Navigation\Page\Mvc($options);
$currentPage->addPage($newpage);
}
}
页面添加成功,但我尝试使用页面的 getHref() 方法在面包屑视图中创建页面的 url:
<?php foreach($this->pages as $page) {?>
<li>
<a href="<?php echo $page->getHref();?>"><?php echo $page->getLabel();?></a>
</li>
<?php }?>
但新添加的页面出现以下错误:
Additional information:
Zend\Navigation\Exception\DomainException
File:
\vendor\zendframework\zendframework\library\Zend\Navigation\Page\Mvc.php:198
Message:
Zend\Navigation\Page\Mvc::getHref cannot execute as no Zend\Mvc\Router\RouteStackInterface instance is composed
我想问题在于我创建页面并将其添加到导航的方式。还有其他方法可以做到这一点或我如何解决此错误?
我想在控制器中而不是在配置文件中添加第三级之后的页面,因为页面的 url 中有参数并且标签是动态的。 欢迎以任何其他方式完成此任务的任何建议。
【问题讨论】:
标签: zend-framework2