繁体   English   中英

Zend-Framework2,表单布局已损坏

[英]Zend-Framework2, Form Layout is Broken

我正在按照Getting Started with Zend Framework 2学习Zend,但是我在表单布局方面遇到了麻烦,它已经坏了: 在此处输入图片说明

如何解决此问题,使其看起来像本教程中的表格: 在此处输入图片说明

AlbumForm代码:

 public function __construct($name = null)
 {
     // we want to ignore the name passed
     parent::__construct('album');

     $this->add(array(
         'name' => 'id',
         'type' => 'Hidden',
     ));
     $this->add(array(
         'name' => 'title',
         'type' => 'Text',
         'options' => array(
             'label' => 'Title',
         ),
     ));
     $this->add(array(
         'name' => 'artist',
         'type' => 'Text',
         'options' => array(
             'label' => 'Artist',
         ),
     ));
     $this->add(array(
         'name' => 'submit',
         'type' => 'Submit',
         'attributes' => array(
             'value' => 'Go',
             'id' => 'submitbutton',
         ),
     ));
 }

和视图代码:

<?php
// module/Album/view/album/album/add.phtml:

$title = 'Add new album';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('artist'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

Zend Framework可以更改元素的样式。 添加“ clear:both;”; 我认为风格会解决问题吗?

    <div class="form_element">
    <?php
        $artist = $form->get('artist');
        echo $this->formRow($artist);
    ?></div>
    <div style="clear:left;"></div>

    <div class="form_element">
    <?php
        $title = $form->get('title');
        echo $this->formRow($title);
    ?></div>
echo '<div style="clear:both;">&nbsp;</div>';
echo $this->formRow($form->get('title'));
echo '<div style="clear:both;">&nbsp;</div>';
echo $this->formRow($form->get('artist'));
echo '<div style="clear:both;">&nbsp;</div>';
echo $this->formSubmit($form->get('submit'));
echo '<div style="clear:both;">&nbsp;</div>';

最简单,最快的方法是添加此CSS。

form label
{
  display: block;
}

请注意,它将与本教程略有不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM