zf2的方式来设置导航栏 [英] zf2 way to set up a navigation bar

查看:182
本文介绍了zf2的方式来设置导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我努力连接ZF1在引导程序中初始化东西的方式和ZF2从配置文件注入东西的方式(似乎)。



  protected function _initNavigation()
{
$ this-> bootstrap('layout');
$ this-> bootstrap('view');

$ navigation = new Zend_Navigation();

// ...添加页面的代码...

$ layout = $ this-> getResource('layout');
$ view = $ layout-> getView();

$ view-> navigation($ navigation);
}



在ZF2中,我甚至不知道开始寻找什么,



我已阅读过以下内容的帖子:

  public function onBootstrap(Event $ e)
{
}

和你可以做的事情的方式:

  $ application = $ e-> getApplication 
$ services = $ application-> getServiceManager();

但是,相当于:

  $ layout = $ this-> getResource('layout'); 
$ view = $ layout-> getView();
$ view-> navigation($ navigation);

我可以在Module中执行此操作,还是更好地在配置文件中进行注入?如果注入,如何?



我已经阅读Rob Allen的教程,并且已经在网上搜索超出教程级代码的例子。我发现的东西(像其他ZF2模块)已经更加面向工作模块(可理解),而不是通过示例,以传达给他人的细微差别...因为我不能找到很多关于这个主题,我'

解决方案

假设有一些小的,基本的东西,我错过了 - 当我看到它, div>

 'service_manager'=> array(
'factories'=> array(
'Navigation'=>'Zend\Navigation\Service\DefaultNavigationFactory',
),
),

在模块配置中添加这一行,它会工作。


I'm struggling to connect the dots between the ZF1 way of initializing things in a bootstrap, and the ZF2 way of injecting things from a config file (seemingly).

To wit, in ZF1, I had something like this in my boostrap:

protected function _initNavigation()
{
    $this->bootstrap('layout');
    $this->bootstrap('view');

    $navigation = new Zend_Navigation();

    // ...code to add pages...

    $layout = $this->getResource('layout');
    $view = $layout->getView();

    $view->navigation($navigation);
}

In ZF2, I'm not even sure what to start looking for, to accomplish something similar.

I've read the posts that refer to:

public function onBootstrap (Event $e)
{
}

and the way that you can do things like:

$application = $e->getApplication();
$services    = $application->getServiceManager();

But, what's the equivalent of:

$layout = $this->getResource('layout');
$view = $layout->getView();
$view->navigation($navigation);

Would I do this in Module, or is it better done in the config file and injected? If injected, how?

I've read Rob Allen's tutorial, and have been searching the net for examples of things that go beyond tutorial-level code. The things that I've found (like other ZF2 modules) have been more oriented toward being working modules (understandably), than being examples through to convey the nuances to others... Since I can't find much on this topic, I'm assuming that there's some small, fundamental thing I'm missing that -- when I see it -- will have it all make sense.

解决方案

'service_manager' => array(
    'factories' => array(
        'Navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
    ),
),

Add up this line in your module config and it will work.

这篇关于zf2的方式来设置导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆