zf2 php设置,php-ZF2 View助手配置

我正在学习Zend Framework 2,并且试图更改表单视图助手的配置.

每个方法都有重新配置主题变量的方法,例如FormCollection helper具有$wrapper变量和setters / getters.

就像Flashmessenger配置(在文档中描述)一样,我在module.config.php中创建了config:

'view_helper_config' => array(

'flashmessenger' => array(

'message_open_format' => '

×
  • ',

    'message_close_string' => '

',

'message_separator_string' => '

'

),

'formcollection' => array(

'wrapper' => '

TEEST %2$s%1$s%3$s',

'label_wrapper' => 'TEST %s',

),

这不行

—-编辑:

我刚刚发现,仅在服务FlashMessengerFactory内部使用了view_helper_config.因此,不可能以这种方式配置视图助手.也许有人有其他建议?

解决方法:

我发现的最好方法(目前)是覆盖现有的帮助程序.因此,通过formCollection的示例,我的module.config.php:

'view_helpers' => array(

'invokables' => array(

'formCollection' => 'MyLibrary\View\Helper\FormCollection',

),

MyLibrary当然是您想要的任何名称空间的地方.在我的视图助手中,只有很少的变量被覆盖:

namespace MyLibrary\View\Helper;

use Zend\Form\ElementInterface;

use Zend\Form\View\Helper\FormCollection as BaseFormCollection;

class FormCollection extends BaseFormCollection {

/**

* This is the default wrapper that the collection is wrapped into

*

* @var string

*/

protected $wrapper = '

TEST %2$s%1$s%3$s';

/**

* This is the default label-wrapper

*

* @var string

*/

protected $labelWrapper = 'TEST 2 %s';

}

用法与之前相同,因为在配置调用内部,我使用了相同的名称:formCollection.

我不确定这是最好的方法.但是它快速,容易实现,并且易于完全覆盖辅助方法(例如render()).

顺便说一句,我认为这是唯一的方法.我们当然可以在使用之前使用辅助方法,例如查看脚本:

$this->formCollection()->setWrapper('new wrapper');

// now its use new wrapper

echo $this->formCollection('collection');

标签:zend-framework2,php

来源: https://codeday.me/bug/20191119/2037921.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值