1
我特林總結我的形式在一個表中,因此HTML輸出的樣子:Zend框架形式表裝飾
<form enctype="application/x-www-form-urlencoded" method="post" action="">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td id="name-label" class="td2 required">Page Name</td>
<td class="td3">
<input type="text" name="name" id="name" value="">
</td>
</tr>
<tr>
<td id="seo_name-label" class="td2 required">Page SEO Name</td>
<td class="td3">
<input type="text" name="seo_name" id="seo_name" value="">
</td>
</tr>
<tr>
<td id="title-label" class="td2 optional">Page Title</td>
<td class="td3">
<input type="text" name="title" id="title" value="">
</td>
</tr>
<tr>
<td id="order-label" class="td2 required">Page SEO Name</label></td>
<td class="td3">
<input type="text" name="order" id="order" value="">
</td>
</tr>
<tr>
<td class="td1" colspan="2" align="center">
<input type="submit" name="Save" id="Save" value="Save">
</td>
</tr>
<input type="hidden" name="csrf" value="0fd12c3fd912bb8f2e59ccae28c886f5" id="csrf">
</table>
</form>
所以我寫了這一點,基於一些搜索的:
class Forms_PageEdit extends Zend_Form
{
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td', 'class' => 'td3')
),
array('Label',
array('tag' => 'td', 'class'=>'td2')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr')
),
);
public function init()
{
$this->setMethod('post');
$this->setDisableLoadDefaultDecorators(true);
$this->removeDecorator('DtDdWrapper');
$this->setDecorators(array(
'FormElements',
array('HtmlTag',array('tag'=>'table', 'width'=>'100%', 'cellspacing' => '0', 'cellpadding'=>'0')),
'Form'
));
// Add an page name
$this->addElement('text', 'name', array(
'label' => STC_Model::getInstance('AdminPhrases')->getPhraseByName('pages_edit_name',3),
'decorators' => $this->elementDecorators,
'required' => true,
'filters' => array('StringTrim'),
));
// add Page SEO Name Element
$this->addElement('text', 'seo_name', array(
'label' => STC_Model::getInstance('AdminPhrases')->getPhraseByName('pages_edit_seo',3),
'decorators' => $this->elementDecorators,
'required' => true,
));
// add Page Title Element
$this->addElement('text', 'title', array(
'label' => STC_Model::getInstance('AdminPhrases')->getPhraseByName('pages_edit_title',3),
'decorators' => $this->elementDecorators,
));
// add Page Title Element
$this->addElement('text', 'order', array(
'label' => STC_Model::getInstance('AdminPhrases')->getPhraseByName('pages_edit_seo',3),
'decorators' => $this->elementDecorators,
'required' => true,
'validators' => array(
array('Digits'),
array('GreaterThan', -1),
),
));
// Add the submit button
$this->addElement('submit', STC_Model::getInstance('AdminPhrases')->getPhraseByName('save'), array(
'decorators' => array(
'ViewHelper',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td', 'class' => 'td1', 'colspan' => '2', 'align' => 'center')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr')
),
),
'ignore' => true,
));
$element = $this->getElement(STC_Model::getInstance('AdminPhrases')->getPhraseByName('save'));
$element->removeDecorator('label');
$element->removeDecorator('DtDdWrapper');
// And finally add some CSRF protection
$this->addElement('hash', 'csrf', array(
'ignore' => true,
));
$element = $this->getElement('csrf');
$element->removeDecorator('label');
$element->removeDecorator('DtDdWrapper');
}
}
但是它確實是這樣的每個標籤:
<td id="name-label"><label for="name" class="td2 required">Page Name</label></td>
我怎樣才能調整,使標籤是我想要的方式?
是的,這將很好地工作。 – Pyromanci
雖然我只是注意到了一些東西。使用echo $ this - > {$ this-> element-> helper}($ this-> element-> getName(),$ this-> element-> getValue(),$ this-> element-> getAttribs())從樣本中他們有頁面廣播組不顯示。 – Pyromanci