gpt4 book ai didi

zend-framework2 - zf2 导航 - 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for navigation'

转载 作者:行者123 更新时间:2023-12-02 00:14:36 25 4
gpt4 key购买 nike

大家好!

我正在学习zf2,并尝试设置一个导航面板(基于:Zend Framework 2: Zend_Navigation),但计算机的答案仍然是:

发生错误执行过程中出现错误;请稍后再试。附加信息:Zend\ServiceManager\Exception\ServiceNotFoundException文件:/var/www/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:453信息:Zend\ServiceManager\ServiceManager::get 无法获取或创建导航实例

module.config.php 包含:

   'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$config = $sm->get('Config');
$navigation = new \Zend\Navigation\Navigation($config->get('navigation'));
return $navigation;
}
),
),

我在主 config/autoload 文件夹中有一个 application.global.php,它看起来像:

<?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
'Album' => array(
'label' => 'Albumlista',
'route' => 'album',
'action' => 'index',
'pages' => array(
array(
'label' => 'Add',
'route' => 'album',
'action' => 'add'
)
)
),
'Application' => array(
'label' => 'Alap alkalmazás',
'route' => 'application',
'action' => 'index',

)
),
),

);

然后我从 Controller 发出这个命令:

$config = $this->getServiceLocator()->get('navigation');

有人可以帮我解决这个问题吗?我读到了 http://adam.lundrigan.ca/2012/07/quick-and-dirty-zf2-zend-navigation/ ,我试过了,我也做了,但是我想结合acl,所以我写了这道题。

感谢您的帮助!

最佳答案

如果您查看 Naviagtion 类的构造函数,它需要一个页面数组或一个 Traversable 对象。您正在传递一个包含页面数组的数组,试试这个:

'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$navigation = new \Zend\Navigation\Service\DefaultNavigationFactory;
$navigation = $navigation->createService($sm);

return $navigation;
}
),
),

默认工厂将通过在您的导航配置下查找默认节点来自动找到您的配置。

您也可以保持原样,但将“默认”节点(在配置中的导航节点下)传递给导航构造函数,因为这是实际的页面定义。

关于zend-framework2 - zf2 导航 - 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for navigation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com