【发布时间】:2019-08-05 10:00:32
【问题描述】:
我对在 zend 中设计表单有点困惑。 我知道我的表单类中有字段,并且应该在视图中完成外观。
在几乎是纯 html 的索引视图中,我没有问题,但在显示我的表单的添加和编辑视图中,我无法更改外观。
我有一个如下视图脚本:
<?php
$title = 'AVB ändern';
$this->headTitle($title);
?>
<h1><?= $this->escapeHtml($title) ?></h1>
<?php
$id= $form->get('id');
$id->setAttribute('class', 'form-control');
$id->setAttribute('placeholder', 'id');
$avbname= $form->get('avbname');
$avbname->setAttribute('class', 'form-control');
$avbname->setAttribute('placeholder', 'avbname');
$vbedingungen= $form->get('vbedingungen');
$vbedingungen->setAttribute('class', 'form-control');
$vbedingungen->setAttribute('placeholder', 'vbedingungen');
$versichererid= $form->get('versichererid');
$versichererid->setAttribute('class', 'form-control');
$versichererid->setAttribute('placeholder', 'versichererid');
$aktiv= $form->get('aktiv');
$aktiv->setAttribute('class', 'form-control');
$aktiv->setAttribute('placeholder', 'aktiv');
$submit = $form->get('submit');
$submit->setAttribute('class', 'btn btn-primary');
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="form-group">
<?= $this->formElement($id) ?>
<?= $this->formElementErrors()->render($id, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
<?= $this->formLabel($avbname) ?>
<?= $this->formElement($avbname) ?>
<?= $this->formElementErrors()->render($avbname, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
<?= $this->formLabel($vbedingungen) ?>
<?= $this->formElement($vbedingungen) ?>
<?= $this->formElementErrors()->render($vbedingungen, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
<?= $this->formLabel($versichererid) ?>
<?= $this->formElement($versichererid) ?>
<?= $this->formElementErrors()->render($versichererid, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
<?= $this->formLabel($aktiv) ?>
<?= $this->formElement($aktiv) ?>
<?= $this->formElementErrors()->render($aktiv, s['class' => 'help-block']) ?>
</div>
<?php
echo $this->formSubmit($submit);
echo $this->formHidden($form->get('id'));
$form->setAttribute('action', $this->url('typavb', ['action' => 'edit']));
echo $this->form()->closeTag();
当然,它显示一个字段在另一个字段之下。 如何连续显示两个字段(带有标签)? 我真的很感激一个好的教程的例子或提示,它展示了如何使用这个 zend3 概念正确地做到这一点。
它甚至是在视图中执行此操作的正确位置还是我需要一个新的 layout.phtml 来处理这种情况?
【问题讨论】:
-
$this->formRow而不是->formLabel&->formElement -
此外,如果您在
*Form类中定义了所有这些类等,那么您可以(从技术上讲)只需执行<?= $this->form($form) ?>即可打印整个表单1 行 ;) -
请发布您真正有用的 cmets 作为答案,以便我接受!
标签: zend-framework zend-form zend-framework3 zend-view