View Helper插件的多个实例? [英] multiple instances of view helper plugin?

查看:100
本文介绍了View Helper插件的多个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Zend 2中实例化视图助手插件的多个实例?

How do I instantiate multiple instances of a view helper plugin in Zend 2?

我想每次从视图中调用$this->pluginName();时都返回一个新实例.

I want to return a new instance every time I call $this->pluginName(); from the view.

如何返回视图插件的新实例?

How do I return a new instance of the view plugin?

推荐答案

将服务名称添加到Module.php中的getViewHelperConfig() shared配置键并将此值设置为false

Add the service name to the getViewHelperConfig() shared configuration key in Module.php and set this value to false

Module.php

function getViewHelperConfig()
{
  return array(
    'shared' => array(
      'MyViewHelper' => false,
    ),
    'factories' => array(
      'MyViewHelper' => 'App\View\Helper\MyViewHelperFactory',
    )
  );
}

通过添加'MyViewHelper' => false,服务管理器(或View Helper插件管理器)将在每次使用该服务时为其创建一个新实例.

By adding 'MyViewHelper' => false, the service manager (or View Helper plugin manager) will create a new instance of that service each time it is used.

文档状态

共享:服务名称/布尔对对的数组,指示是否应共享服务.默认情况下,ServiceManager假定所有服务都是共享的,但是您可以在此处指定布尔布尔值,以指示应返回新实例.

shared An array of service name/boolean pairs, indicating whether or not a service should be shared. By default, the ServiceManager assumes all services are shared, but you may specify a boolean false value here to indicate a new instance should be returned.

这篇关于View Helper插件的多个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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