【问题标题】:Zend Form, table decoratorsZend Form,餐桌装饰器
【发布时间】:2010-12-10 21:30:22
【问题描述】:

我很难按照我需要的方式装饰 Zend 窗体。这是我需要的 HTML 结构:

<table>
<thead><tr><th>one</th><th>two</th><th>three</th><th>four</th></thead>
<tbody>
<tr>
 <td><input type='checkbox' id='something'/></td>
 <td><img src='src'/></td>
 <td><input type='text' id='something'/></td>
 <td><input type='radio' group='justonegroup'/></td>
</tr>
<tr>
 <td><input type='checkbox' id='something'/></td>
 <td><img src='src'/></td>
 <td><input type='text' id='something'/></td>
 <td><input type='radio' group='justonegroup'/></td>
</tr>
</tbody>
</table>

正文中的行数由表单类中的循环结构决定。当然,所有 ID 都是唯一的。表单中的所有单选按钮都属于一组。我的问题实际上是我不确定如何在我的表中创建对象 Zend_Form_Element_MultiCheckbox 和 Zend_Form_Element_Radio 并为其设置样式。我将在哪里/如何将适当的装饰器应用于复选框和单选按钮以具有像上面这样的表单结构?

到目前为止我的表单类:

class Form_ManageAlbums extends Zend_Form
{
  public function __construct($album_id)
  {
    $photos = Model_DbTable_Photos::getAlbumPhotos($album_id);

    $selector = new Zend_Form_Element_MultiCheckbox('selector');

    $radio = new Zend_Form_Element_Radio('group');

    $options = array();

    while($photo = $photos->fetchObject())
    {

      $options[$photo->id] = '';

      $image = new Zend_Form_Element_Image('image'.$photo->id);
      $image->setImageValue('/dog/upload/'.$photo->uid.'/photo/'.$photo->src);

      $caption = new Zend_Form_Element_Text('caption'.$photo->id);
      $caption->setValue($photo->caption);

      $this->addElements(array($image, $caption));
    }

    $selector->addMultiOptions($options);
    $radio->addMultiOptions($options);

    $this->addElement($selector);

  $this->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'table')),
        'Form'
    ));
  }
}

我已经为 td 和 tr 尝试了一些装饰器的组合,但迄今为止没有成功。

感谢您的帮助,非常感谢。 JP列瓦茨

【问题讨论】:

    标签: zend-framework zend-form zend-decorators


    【解决方案1】:

    这里是使用 zend 表单装饰器创建表格布局的教程:Tutorial - Create Zend Framework Form with table layout using decorators

    【讨论】:

      【解决方案2】:

      看看这个devzone article。它将解释装饰器的工作原理,让您知道发生了什么以及如何编写自己的装饰器,然后以表格示例结束。

      Zend_Form 的作者在这两篇文章中对装饰器做了一些很好的解释:

      【讨论】:

      • @KevinPeno 看起来 Zend 有了一个新网站。格式已损坏,但请查看this updated page。我已经更新了原帖。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 2011-10-11
      • 2013-07-25
      相关资源
      最近更新 更多