我在我的项目中使用了zend framework3。我可以按照文档的link创建静态导航
现在我必须从数据库中获取菜单数据,然后创建导航。为此,我在module.config.php中提供了配置,这是相册模块的配置文件。
<?php
namespace Album;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\Navigation\Service\DefaultNavigationFactory;
use Album\Navigation\AlbumNavigationFactory;
return [
'controllers' => [
'factories' => [
Controller\AlbumController::class => Factory\AlbumControllerFactory::class,
Controller\IndexController::class => InvokableFactory::class,
],
],
// Add this section:
'service_manager' => [
'factories' => [
'navigation' => Navigation\AlbumNavigationFactory::class,
Model\AlbumTable::class => Factory\AlbumTableFactory::class,
],
],
// The following section is new and should be added to your file:
'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumController::class,
'action' => 'index',
],
],
],
'index' => [
'type' => Segment::class,
'options' => [
'route' => '/index[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];在zend framework2中,我们简单地将一个带有工厂类的导航键作为
return array(
'factories' => array(
'Navigation' => 'Album\Navigation\AlbumNavigationFactory'
),
);在zend framework3中,我正在做与下面相同的事情
'service_manager' => [
'factories' => [
'navigation' => Navigation\AlbumNavigationFactory::class,
Model\AlbumTable::class => Factory\AlbumTableFactory::class,
],
],我正在使用导航\AlbumNavigationFactory::类来调用factory来获取数据。但是我不能得到导航。任何帮助都将不胜感激。
发布于 2017-03-05 04:02:33
cd。
在module.config.php中
'navigation' => array(
'default' => array(
'blog' => array(
'label' => 'Blog',
'route' => 'blog-front',
'controller' => 'blog',
'action' => 'index',
)
)
)https://stackoverflow.com/questions/40662171
复制相似问题