scripting - Zend Form - 从表单类中提取标签值以在 View 脚本中显示的方法?

标签 scripting view label zend-form

我正在切换表单以使用 View 脚本作为装饰器。 到目前为止我看到的示例在 View 脚本中执行以下操作:

<td><label for='textEmail'>Email:</label></td>
<td><?php echo $this->element->textEmail; ?></td>

我想找到一种方法,让表单对象中的文本也显示在标签中。

class RegisterForm extends Zend_Form {
public function init () {
    $this->setAction('')
        ->setMethod('post')
        ->setAttrib('id','formRegister');

    $this->addElement('text', 'textEmail', array('label' => 'Email: '));
    $oEmail = $this->getElement('textEmail')
        ->setRequired(true)
        ->addFilter('StringTrim')
        ->addValidator('EmailAddress');
    $oEmail->setDecorators(array('ViewHelper', 'Errors'));

    $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/RegisterForm.phtml'))));
    }
}

以上是我的表单对象的定义方式。 有谁知道如何访问定义的标签值? 也许采用以下格式?

<?php echo $this->element->textEmail->label; ?>

这当然行不通。 :p 谢谢~

最佳答案

$this->元素->getLabel()

这是我的标准字段 View 脚本:

<div class="field<?php if($this->element->hasErrors()): ?> errors<?php endif; ?>" id="field_<?php echo $this->element->getId(); ?>">
    <?php if (0 < strlen($this->element->getLabel())) : ?>
        <?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?>
    <?php endif; ?>
    <span class="value"><?php echo $this->{$this->element->helper}(
        $this->element->getName(),
        $this->element->getValue(),
        $this->element->getAttribs()
    ) ?></span>
    <?php if ($this->element->hasErrors()) : ?>
        <?php echo $this->formErrors($this->element->getMessages()); ?>
    <?php endif; ?>
    <?php if (0 < strlen($this->element->getDescription())) : ?>
        <span class="hint"><?php echo $this->element->getDescription(); ?></span>
    <?php endif; ?>
</div>

关于scripting - Zend Form - 从表单类中提取标签值以在 View 脚本中显示的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398102/

相关文章:

linux - 使用awk以编号格式将单行拆分为多行

view - 在extjs4中如何获取另一个 View 中一个 View 的菜单项以启用它

android - 如何在具有可聚焦 View (例如按钮)的 ListView 中获取点击反馈

iphone - 如何在 iOS 运行时创建动态标签和按钮?

windows - for 循环不能正常工作?我做错了什么?

python - 奇怪的 python 打印行为

Swift 以编程方式向标签添加约束

javascript - 根据 json 标签有条件地更改 json 属性 - javascript

javascript - 如何对 PouchDB 进行压力测试

dynamic - View 中的 Couchbase 通配符/变量键