如何将控件的标签 属性 访问到 ZF2 中的视图

How can I access label property for a control into a view in ZF2

这是视图文件中的代码,index.phtml:

<?php echo $this->formRow($form->get('daterange'));?>

这是我从表单文件中提取的代码:

    $this->add(array(
        'type' => 'text',
        'name' => 'daterange',
        'options' => array(
            'label' => 'Start Time'
        ),
        'attributes' => array(
            'id' => 'daterange',
            'class' => 'form-control'
        ),
    ));

如何只访问日期范围控件的标签 属性?我需要它,因为我想改进我的布局。

因为 $form->get('daterange') 是 Zend_Form_Element 您可以使用 getLabel() 从元素中检索标签。

$form->get('daterange')->getLabel(); // 应该可以解决问题。

但增强布局的最佳方式可能是向元素添加自定义装饰器并通过 Zend_Form_Element render() 函数触发它。