gpt4 book ai didi

zend-framework - 使用标签装饰器添加所需标记的最佳方法是什么 - Zend

转载 作者:行者123 更新时间:2023-12-04 06:37:42 24 4
gpt4 key购买 nike

我有一个关于使用 Zend_Form_Decorator_Label 的问题,为了在需要表单元素时获得以下结果,我需要获取 Label-text *,我想知道如何以最可重用的方式实现它?

是编写新的装饰器还是重写 zend_View_helper_FormLabel ?也许还有其他方法可以实现这一目标?

任何帮助将不胜感激。

最佳答案

您可以在创建装饰器时添加以下选项之一:

  • optionalPrefix:当元素是可选时使用的标签前缀
  • optionalSuffix:当元素可选时使用的标签后缀
  • requiredPrefix:需要元素时使用的标签前缀
  • requiredSuffix:需要元素时使用的标签后缀

代码示例:

$elementDecorators = array(
'ViewHelper',
array('Label', array('requiredSuffix' => ' *')),
);

$userName = new Zend_Form_Element_Text('userName');
$userName->setDecorators($elementDecorators);
$userName->setLabel('User Name');

或者,您也可以在现有装饰器上显式设置后缀/前缀:

$userName->getDecorator('Label')->setReqSuffix(' *');
$userName->getDecorator('Label')->setOptSuffix('(Optional) ');

关于zend-framework - 使用标签装饰器添加所需标记的最佳方法是什么 - Zend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com