1

我想在 Skeleton Application (ZF2) 中建立一个菜单。我做了一个单独的模块Navigation。在 Navigation Controller 写了一段代码:

namespace Navigation\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Navigation\Navigation;

class NavigationController extends AbstractActionController
{
public function indexAction()
{   

    $container = new \Zend\Navigation\Navigation(array(
     array(
        'label' => 'Album',
        'controller' => 'album',
        'action' => 'index',
        'route' => 'album',
         )
));

    $navigation = new \Zend\View\Helper\Navigation\Menu();

    $navigation->renderMenu($container);

    return new ViewModel(array('navigation'=>$navigation));
}}

并得到错误: Zend\Navigation\Page\Mvc::getHref cannot execute as no Zend\Mvc\Router\RouteStackInterface instance is composed 在文件:\vendor\zendframework\zendframework\library\Zend\Navigation\Page\Mvc.php:186

怎么解决?

4

2 回答 2

0

点击链接

从数据库下载 ZF2 动态导航。有添加、编辑、删除菜单项的功能。

于 2014-09-28T16:09:00.517 回答
0

似乎您的导航模块中未定义路线“专辑” 。需要在 Navigation 模块的 module.config.php 中设置路由。我认为,路由需要包含一个附加参数 :module ,它指向应用程序模块。

于 2012-12-11T08:15:15.513 回答