问题
Hy everybody!
I am learning zf2, and trying to set up a navigation panel(based on: Zend Framework 2: Zend_Navigation), but the answer from the computer is still:
An error occurred An error occurred during execution; please try again later. Additional information: Zend\ServiceManager\Exception\ServiceNotFoundException File: /var/www/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:453 Message: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for navigation
The module.config.php contain:
'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$config = $sm->get('Config');
$navigation = new \Zend\Navigation\Navigation($config->get('navigation'));
return $navigation;
}
),
),
I have an application.global.php in the main config/autoload folder which is looks like:
<?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',
)
),
),
);
And from the controller i give this command:
$config = $this->getServiceLocator()->get('navigation');
Could somebody help me to solve this problem? I read about http://adam.lundrigan.ca/2012/07/quick-and-dirty-zf2-zend-navigation/ , I tried it, and I did it, but I would like to combine with acl so that I wrote this question.
Thanks for every help!
回答1:
If you look at the contructor for the Naviagtion class it required either an array of Pages or a Traversable object. You are passing in an array with an array of pages inside, try this:
'servicemanager' => array(
'factories' => array(
'navigation' => function($sm) {
$navigation = new \Zend\Navigation\Service\DefaultNavigationFactory;
$navigation = $navigation->createService($sm);
return $navigation;
}
),
),
The default factory will automatically find your config by looking for the default node under your navigation config.
You could alternatively keep it the way you have, but pass in the "default" node (under the Navigation node in the config) to the Navigation contructor as this is the actual page definition.
回答2:
My problem solved when I changed the following line in application.config.php
'config/autoload/{,*.}{global,local}.php', //[This is default setting]
config_glob_paths' => array( '<PUT_ABSOLUTE_PATH_HERE>{,*.}{global,local}.php', ),
in place of 'config/autoload' full path instead of the relative path.
回答3:
I think you are using view helper
$this->escape($this->somevar); //this is zf1 view helper
in zf2 you can escape using the view helper
$this->escapeHtml($this->somevar);
来源:https://stackoverflow.com/questions/13879915/zf2-navigation-zend-servicemanager-servicemanagerget-was-unable-to-fetch-or