zend-framework - View 助手插件的多个实例?

标签 zend-framework zend-framework2 zend-view

如何在 Zend 2 中实例化 View 帮助器插件的多个实例?

我想每次从 View 调用 $this->pluginName(); 时返回一个新实例。

如何返回 View 插件的新实例?

最佳答案

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

模块.php

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

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

documentation states

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.

关于zend-framework - View 助手插件的多个实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21272055/

相关文章:

zend-framework - Zend Framework 应用程序中的事件

zend-framework - Zend_Validate_Between 与 ip2long

php - dompdf 不能在 zend 框架 2 中工作

php - zend 框架找不到帮助程序 View 文件。出现 'Plugin by name was not found' 错误

php - 为什么这段代码全是斜杠

PHP 强制下载返回损坏的文件

php - 如何填充 zend 表单选择元素?

php - 配置 ZF2 view_manager 以加载 2 个单独的模板映射

php - ZF 2 Zend\Form\Element\Date 不在 View 中创建日历

php - Zend View Helper Navigation 移除事件分支,因此面包屑不会显示