我在我的項目中使用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' ), 我想從數據庫中得到這個數組,你有什麼想法我怎麼能從數據庫中得到這個數組? –