Zend framework2 zf2导航-';Zend\ServiceManager\ServiceManager::get无法获取或创建导航的实例';
大家好 我正在学习zf2,并试图设置一个导航面板(基于:),但计算机给出的答案仍然是: 发生了一个错误 执行过程中发生错误;请稍后再试。 其他信息: Zend\ServiceManager\Exception\ServiceNotFoundException 文件: /var/www/zf2 tutorial/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:453 信息: Zend\ServiceManager\ServiceManager::get无法获取或创建用于导航的实例 module.config.php包含:Zend framework2 zf2导航-';Zend\ServiceManager\ServiceManager::get无法获取或创建导航的实例';,zend-framework2,Zend Framework2,大家好 我正在学习zf2,并试图设置一个导航面板(基于:),但计算机给出的答案仍然是: 发生了一个错误 执行过程中发生错误;请稍后再试。 其他信息: Zend\ServiceManager\Exception\ServiceNotFoundException 文件: /var/www/zf2 tutorial/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:453 信息: Zend
'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',
)
),
),
);
有人能帮我解决这个问题吗?
我读过,我试过,我做到了,但我想结合acl,所以我写了这个问题
谢谢你的帮助 如果查看导航类的构造函数,它需要一个页面数组或一个可遍历对象。如果要传入一个包含页面数组的数组,请尝试以下操作:
'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$navigation = new \Zend\Navigation\Service\DefaultNavigationFactory;
$navigation = $navigation->createService($sm);
return $navigation;
}
),
),
默认工厂将通过在导航配置下查找默认节点自动查找配置
您也可以保持原有的方式,但将“默认”节点(在配置中的导航节点下)传递给导航构造函数,因为这是实际的页面定义。当我在
application.config.php中更改以下行时,我的问题得到了解决
'config/autoload/{,*.}{global,local}.php', //[This is default setting]
config_glob_paths' => array( '<PUT_ABSOLUTE_PATH_HERE>{,*.}{global,local}.php', ),
'config/autoload/{,*.}{global,local}.php',//[这是默认设置]
config_glob_path'=>数组('{,*.}{global,local}.php',),
取代了'config/autoload'
完整路径而不是相对路径。我认为您使用的是视图帮助器
$this->escape($this->somevar)//这是zf1视图辅助程序
在zf2中,可以使用视图辅助对象进行转义
$this->escapeHtml($this->somevar) 你能解释一下你在这里插入的绝对路径是什么吗?
'config/autoload/{,*.}{global,local}.php', //[This is default setting]
config_glob_paths' => array( '<PUT_ABSOLUTE_PATH_HERE>{,*.}{global,local}.php', ),