我在我的项目中使用zend framework3。我可以按照文档创建静态导航link在zf3中创建动态导航
现在我必须从数据库中提取菜单数据,然后创建导航。 为此我正在使用我已提供配置到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的框架3我在做同样的事情,下面
'service_manager' => [
'factories' => [
'navigation' => Navigation\AlbumNavigationFactory::class,
Model\AlbumTable::class => Factory\AlbumTableFactory::class,
],
],
我使用导航\ AlbumNavigationFactory :: class来调用工厂来获取数据。 但我无法获得导航。任何帮助,将不胜感激。
@Andry布埃诺我已经检查所提供的URL。我的问题是我们在导航键中传递的数组为 'navigation'=> array( 'default'=> array(array( 'label'=>'Home', 'route'=>'home' , 'icon'=>'glyphicon glyphicon-home' ), 我想从数据库中得到这个数组,你有什么想法我怎么能从数据库中得到这个数组? –