以下代码的zend表单装饰器是什么?

时间:2011-08-29 09:25:36

标签: zend-framework decorator

装饰者应该将这两个元素并排放置。通常它会渲染默认的zend的“dl-dt-dd”结构。我需要在dt中使用共同的单个标签的同一个dd中的这两个元素。

$card_expmonth = new Zend_Dojo_Form_Element_FilteringSelect('card_expmonth');
$card_expmonth->setLabel('Card Expiration')
    ->setMultiOptions(array(1=>'1','2','3','4','5','6','7','8','9','10','11','12'))
    ->setAttrib('style','width:100px;')
    ->setRequired(true);

$card_expyear = new Zend_Dojo_Form_Element_FilteringSelect('card_expyear');
$card_expyear->setMultiOptions(array(2011=>'2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025'))
    ->setAttrib('style','width:100px;')
    ->setRequired(true);

请有人帮帮我。

2 个答案:

答案 0 :(得分:1)

$card_expmonth->setDecorators(array(
    'ViewHelper',
    array(array('dd' => 'HtmlTag'), array('tag' => 'dd', 'openOnly' => true)),
    array('Label', array('tag' => 'dt')),
    array(array('dl' => 'HtmlTag'), array('tag' => 'dl', 'openOnly' => true))
));

$card_expyear->setDecorators(array(
    'ViewHelper',
    array(array('dd' => 'HtmlTag'), array('tag' => 'dd', 'closeOnly' => true)),
    array(array('dl' => 'HtmlTag'), array('tag' => 'dl', 'closeOnly' => true))
));

未经测试。告诉我它是否不起作用。

另请阅读http://devzone.zend.com/article/3450

答案 1 :(得分:0)

我建议你不要在这种情况下使用装饰器:

$card_expmonth->setDecorators(array('ViewHelper'));
$card_expyear->setDecorators(array('ViewHelper'));

在视图中:

<form action="<?php echo $form->getAction() ?>"
      method="<?php echo $form->getMethod() ?>"
      enctype="<?php echo $form->getEnctype() ?>"
      accept-charset="<?php echo $form->getAttrib('accept-charset') ?>"
      id="<?php echo $form->getId() ?>">
    <dl>
        <dt><?php echo $form->card_expmonth->getLabel() ?></dt>
        <dd>
            <?php echo $form->card_expmonth ?>
            <?php echo $form->card_expyear ?>
        </dd>
    </dl>
</form>

此外,您应该关心错误输出。