Php 为什么Zend_表单会产生?

Php 为什么Zend_表单会产生?,php,zend-framework,forms,zend-form,Php,Zend Framework,Forms,Zend Form,为什么要生产Zend_Form? 我知道它默认会产生装饰器,但它们为什么要使用装饰器呢 谢谢装饰器是包装表单元素的一种方法 在Zend/Form.php中,您可以看到默认配置: /** * Load the default decorators * * @return void */ public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) {

为什么要生产Zend_Form? 我知道它默认会产生装饰器,但它们为什么要使用装饰器呢


谢谢

装饰器是包装表单元素的一种方法

在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;
}
Plus 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')),
));
有一个非常简单的播客,解释装饰师是如何工作的:


查找名为:Zend_Form Decorators Explained的视频。Decorators是包装表单元素的一种方法

在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;
}
Plus 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')),
));
有一个非常简单的播客,解释装饰师是如何工作的:


查找名为“Zend_Form Decorators Explained”的视频

非常感谢,但我的问题是为什么,而不是如何。我的意思是我不知道为什么应该由zend_表单添加dd标记-所以我问是否存在这样的特殊原因它只是一个搜索引擎和屏幕阅读器友好的表单呈现。主要是因为它即使没有样式也能正确呈现。它还具有som语义。dt术语-标签和dd定义-元素。可以理解的用户名是这个元素:我知道换个方式会更好,但看起来会很奇怪;非常感谢,但我的问题是为什么,而不是如何。我的意思是我不知道为什么应该由zend_表单添加dd标签-所以我问是否存在特殊原因它只是一个搜索引擎和屏幕阅读器友好的表单呈现。主要是因为即使没有样式,它也能正确呈现。它还具有som语义。dt术语-标签和dd定义-元素。可以理解的用户名是这个元素:我知道换个方式会更好,但看起来会很奇怪;