大家好!
我正在学习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;
}
),
),我在主application.global.php /autoload文件夹中有一个配置,如下所示:
<?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',
)
),
),
);在控制器上,我给出了这个命令:
$config = $this->getServiceLocator()->get('navigation');有人能帮我解决这个问题吗?我读过关于http://adam.lundrigan.ca/2012/07/quick-and-dirty-zf2-zend-navigation/的文章,我尝试过,我也这样做了,但我想结合使用acl,所以我写了这个问题。
感谢大家的帮助!
发布于 2013-02-12 17:31:46
如果您查看Naviagtion类的构造器,它需要一个页面数组或一个可遍历的对象。您正在传入一个包含页面数组的数组,请尝试如下所示:
'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$navigation = new \Zend\Navigation\Service\DefaultNavigationFactory;
$navigation = $navigation->createService($sm);
return $navigation;
}
),
),默认工厂将通过查找导航配置下的默认节点来自动查找您的配置。
您也可以保持原来的方式,但将"default“节点(在配置中的导航节点下)传递给导航构造器,因为这是实际的页面定义。
发布于 2014-04-01 16:18:40
当我在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'的完整路径,而不是相对路径。
发布于 2016-02-10 04:24:47
我认为您正在使用view helper。
$this->转义($this->某些事件);//这是zf1视图帮助器
在zf2中,您可以使用视图帮助程序进行转义
$this->escapeHtml($this->somevar);
https://stackoverflow.com/questions/13879915
复制相似问题