脚本宝典收集整理的这篇文章主要介绍了zend-framework2 – ZF2 – 在调用控制器之前将页面注入导航,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
的Nodeid,
ParentNodeId,
Name_de,
Name_en,
模块名,
foreignkey_ContentLinks,
在此表中条目如下所示:
6,
1,
Veranstaltung-21-02-2013,
事件21-02-2013,
活动,
682
整个树应该在我的导航中结束(完全也在我的路由中).我不想在某个控制器中添加它,因为我的应用程序由一大堆模块组成,我希望在所有模块中访问该信息.
我已经尝试在global.PHP中注入它,但无济于事,因为我不能在我的数据库适配器或该阶段的任何其他重要类.
有关最佳实践的想法或链接吗?
<?PHP namespace Application\Navigation\Service; use Zend\Navigation\Service\AbstractNavigationFactory; use Zend\ServiceManager\ServiceLocatorInterface; class CmsnavigationFactory extends AbstractNavigationFactory { /** * @param ServiceLocatorInterface $serviceLocator * @return array * @throws \Zend\Navigation\Exception\InvalidargumentException */ PRotected function getPages(ServiceLocatorInterface $serviceLocator) { if (null === $this->pages) { $application = $serviceLocator->get('Application'); $routeMatch = $application->getMvcEvent()->getRoutematch(); $router = $application->getMvcEvent()->getRouter(); // get your pages From wherever... $pages = $this->getPagesFromDB(); $this->pages = $this->injectcomponents($pages,$routeMatch,$router); } return $this->pages; } public function getName() { // this isn't used if fetching from db,IT's just here to keep the abstract factory happy return 'cms'; } }
将工厂添加到服务管理器,就像您对其他容器一样
'service_manager' => array( 'factories' => array( 'CmsNavigation' => 'Application\Navigation\Service\CmsNavigationFactory',),
并以相同的方式将其与导航视图助手一起使用
<?PHP echo $this->navigation()->menu('CmsNavigation'); ?>
以上是脚本宝典为你收集整理的zend-framework2 – ZF2 – 在调用控制器之前将页面注入导航全部内容,希望文章能够帮你解决zend-framework2 – ZF2 – 在调用控制器之前将页面注入导航所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。