2

View Script をデコレータとして使用するようにフォームを切り替えようとしています。これまでに見た例では、ビュー スクリプトで次のことを行います。

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

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'))));
    }
}

上記は、フォーム オブジェクトの定義方法です。定義されたラベル値にアクセスする方法を知っている人はいますか? おそらく次の形式で?

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

当然、それはうまくいきません。:p ありがとう~

4

1 に答える 1

6

$this->element->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>
于 2010-01-27T14:57:20.503 に答える