Zend-Framework2,表单布局已损坏

时间:2016-03-06 08:24:48

标签: php zend-framework2

我正在通过关注Getting Started with Zend Framework 2教程来学习Zend,但我面临着表单布局的问题,它已被打破: enter image description here

如何修复此问题以使其像教程中的表单一样: enter image description here

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();

4 个答案:

答案 0 :(得分:0)

Zend Framework有可能改变元素的风格。添加&#34;清除:两者;&#34;风格我觉得会解决问题吗?

答案 1 :(得分:0)

    <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>

答案 2 :(得分:0)

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>';

答案 3 :(得分:0)

最简单快捷的方法是添加此css ..

form label
{
  display: block;
}

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