Why Zend_Form produce <dt id="label-id"> <dd id="elem-id">?
Why Zend_Form produce <dl> <dt id="label-id"> <dd id="elem-id"> </dl>
开发者_运维技巧?
(I understand that its produce by default decorators, but why and for what they used? )
Thanks
The decorators are a way to wrap your form elements.
In Zend/Form.php you can see the default configuration:
/**
* 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;
}
Plus Zend/FormElements.php uses its own decorators:
/**
* 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;
}
You can overwrite the default decorators for each element or for the whole form:
$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')),
));
There is a really easy podcast explaining how decorators work:
http://feeds.feedburner.com/ZendScreencastsVideoTutorialsAboutTheZendPhpFrameworkForiPhone
Look for the video called: Zend_Form Decorators Explained
精彩评论