Jay*_*era 2 scripting label view zend-form
我正在切换表单以使用View Script作为装饰器.到目前为止我看到的示例在View脚本中执行以下操作:
<td><label for='textEmail'>Email:</label></td>
<td><?php echo $this->element->textEmail; ?></td>
Run Code Online (Sandbox Code Playgroud)
我想找到一种方法让文本显示在Form对象的标签中.
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'))));
}
}
Run Code Online (Sandbox Code Playgroud)
以上是我的表单对象的定义方式.有人知道如何访问定义的标签值吗?可能采用以下格式?
<?php echo $this->element->textEmail->label; ?>
Run Code Online (Sandbox Code Playgroud)
当然这不起作用.:p谢谢〜
$这个 - >元素 - > getLabel()
这是我的标准字段的视图脚本:
<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>
Run Code Online (Sandbox Code Playgroud)