我正在通过关注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();
答案 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;"> </div>';
echo $this->formRow($form->get('title'));
echo '<div style="clear:both;"> </div>';
echo $this->formRow($form->get('artist'));
echo '<div style="clear:both;"> </div>';
echo $this->formSubmit($form->get('submit'));
echo '<div style="clear:both;"> </div>';
答案 3 :(得分:0)
最简单快捷的方法是添加此css ..
form label
{
display: block;
}
请注意,它与教程略有不同。