1
爲什麼Zend_Form產生<dl> <dt id="label-id"> <dd id="elem-id"> </dl>
? (據我所知,它的產生由缺省的裝飾,但爲什麼和他們使用了什麼?)爲什麼Zend_Form產生<dt id =「label-id」><dd id =「elem-id」>?
感謝
爲什麼Zend_Form產生<dl> <dt id="label-id"> <dd id="elem-id"> </dl>
? (據我所知,它的產生由缺省的裝飾,但爲什麼和他們使用了什麼?)爲什麼Zend_Form產生<dt id =「label-id」><dd id =「elem-id」>?
感謝
的裝飾器是在包裝你的表單元素的方式。
在Zend公司/ form.php的,你可以看到默認的配置:
/**
* Load the default decorators
*
* @return void
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return $this;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
->addDecorator('Form');
}
return $this;
}
加的Zend/FormElements.php使用它自己的裝飾:
/**
* Load default decorators
*
* @return Zend_Form_Element
*/
public function loadDefaultDecorators()
{
if ($this->loadDefaultDecoratorsIsDisabled()) {
return $this;
}
$decorators = $this->getDecorators();
if (empty($decorators)) {
$this->addDecorator('ViewHelper')
->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array('tag' => 'dd',
'id' => $this->getName() . '-element'))
->addDecorator('Label', array('tag' => 'dt'));
}
return $this;
}
可以覆蓋每一個缺省的裝飾元素或整個表單:
$element->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')),
array(array('td' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
));
有一個非常簡單的播客解釋如何裝飾工作:
http://feeds.feedburner.com/ZendScreencastsVideoTutorialsAboutTheZendPhpFrameworkForiPhone
尋找影片叫:Zend_Form的裝飾解釋
非常感謝你,但我的問題是,爲什麼不how.I意味着我不知道爲什麼要DD標籤由zend_form添加 - 洙我問是否存在特殊原因 – Yosef 2010-07-14 14:40:46
這只是一個搜索引擎和屏幕閱讀器友好的表單形式。 – jantimon 2010-07-15 07:40:31
主要是因爲即使沒有樣式也能正確渲染。它也有它的som語義。 dt(term) - 標籤和dd(定義) - 元素。可以閱讀「用戶名是這個元素」:)我知道這將是更好的另一種方式,但它看起來很奇怪;) – 2011-04-05 19:15:08