1

次の HTML が必要です。

<form name="input" action="post" method="get">
    <label>1</label><input type="radio" value="1" name="rating" />
    <label>2</label><input type="radio" value="2" name="rating" /> 
    <label>3</label><input type="radio" value="3" name="rating" /> 
    <label>4</label><input type="radio" value="4" name="rating" /> 
    <label>5</label><input type="radio" value="5" name="rating" /> 
    <input type="submit" value="Submit" />
</form>

私の zend フレームワーク プロジェクトでは、Zend_Form でこれを行うにはどうすればよいですか? 特定のブログのサンプルコードをいくつか試してみましたが、うまくいきません..

ありがとう

4

1 に答える 1

6

ViewScript デコレータを使用して、必要なマークアップを作成できます。フォーム クラスで radio 要素を作成し、setDecorators メソッドを使用して、この要素にビュースクリプト デコレータを割り当てます。

$element = new Zend_Form_Element_Radio('rating');
$element->addMultiOptions(array(
    '1' => '1',
    '2' => '2',
    '3' => '3',
    '4' => '4',
    '5' => '5'
))
    ->setDecorators(array(array('ViewScript', array('viewScript' => 'radio.phtml'))));
$this->addElement($element);

次に、次のように、views/scripts ディレクトリ内に radio.phtml ファイルを作成します。

<?php foreach ($this->element->getMultiOptions() as $label => $value) : ?>
<label><?php echo $label; ?></label><input type="radio" value="<?php echo $value; ?>" name="<?php echo $this->element->getName(); ?>" />
<?php endforeach; ?>
于 2012-05-03T14:56:46.990 に答える