简单的例子HOWTO使导航
文件路径模块/应用/配置/ module.config.php
<?php
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'default' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:namespace[/:controller[/:action]]]',
'constraints' => array(
'namespace' => '[a-zA-Z][a-zA-Z0-9_-]*',
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
//'locale' => 'da_DK',
'namespace' => 'Application',
'controller' => 'index',
'action' => 'index',
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'index' => 'Application\Controller\IndexController',
'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
'service_manager' => array(
'factories' => array(
'Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
接下来是导航配置
<?php
/*
* This file path config/autoload/application.global.php
*/
return array(
// All navigation-related configuration is collected in the 'navigation' key
'navigation' => array(
// The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
'default' => array(
// And finally, here is where we define our page hierarchy
'home' => array(
'label' => 'Home',
'route' => 'home',
),
'news' => array(
'label' => 'News',
'controller' => 'news',
'action' => 'news',
'route' => 'default',
'pages' => array(
'add' => array(
'label' => 'Add news',
'controller' => 'news', /* or create a seperate route insteed*/
'action' => 'add',
'route' => 'default',
),
),
),
),
),
);
而去年回波导航布局文件或查看文件
例如模块/应用/视图/布局/ layout.phtml
<?php echo $this->navigation('Navigation')->menu(); ?>
它给了我这样的例外:“Zend的\的ServiceManager \的ServiceManager ::得到无法获取或创建导航实例” @Behzadsh我 – Behzadsh 2012-08-25 13:34:10
了。 – ioanb7 2012-11-08 12:39:32