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 ありがとう~