Zend framework Zend表单警告:htmlspecialchars()。。。当元素\文本设置为数组时

Zend framework Zend表单警告:htmlspecialchars()。。。当元素\文本设置为数组时,zend-framework,warnings,zend-form,zend-form-element,Zend Framework,Warnings,Zend Form,Zend Form Element,我会尽量说清楚的。 我使用zend表单和文本元素,该元素使用->setIsArray(true) 我将元素设置为数组,因为我正在使用javascript动态添加新元素。 在html中,它表示: <input type="text" name="submenu2[]" /> 我在“应用程序路径”/../library/Custom/Elements”中创建了您给我的类 我得到: 致命错误:找不到类“自定义元素\u数组元素” 这是: 创建您自己的元素类型,该元素类型将接受一个值数组,并

我会尽量说清楚的。 我使用zend表单和文本元素,该元素使用->setIsArray(true)

我将元素设置为数组,因为我正在使用javascript动态添加新元素。
在html中,它表示:

<input type="text" name="submenu2[]" />
我在“应用程序路径”/../library/Custom/Elements”中创建了您给我的类
我得到:

致命错误:找不到类“自定义元素\u数组元素”

这是:

创建您自己的元素类型,该元素类型将接受一个值数组,并且 然后是一个将输出各种输入项的装饰器

class My_Element_ArrayElement extends Zend_Form_Element 
{ 
    public function init() 
    { 
        $this->addPrefixPath('My_Decorator', 'My/Decorator/', 'decorator'); 
    } 

    public function setValue($value) 
    { 
        $this->_value = (array) $value; 
    } 

    public function getValues() 
    { 
        return $this->_value; 
    } 


    public function loadDefaultDecorators() 
    { 
        if ($this->loadDefaultDecoratorsIsDisabled()) { 
            return; 
        } 

        $decorators = $this->getDecorators(); 
        if (empty($decorators)) { 
            $this->addDecorator('ArrayElement'); 
        } 
    } 

} 

class My_Decorator_ArrayElement extends Zend_Form_Decorator_Abstract 
{ 
    public function render($content) 
    { 
        $element = $this->getElement(); 
        $view    = $element->getView(); 
        $markup  = ''; 
        $name    = $element->getName() . '[]'; 

        foreach ($element->getValues() as $value) { 
            $markup .= $view->formHidden($name, $value) . "\n"; 
        } 

        $separator = $this->getSeparator(); 
        switch ($this->getPlacement()) { 
            case 'PREPEND': 
                return $markup . $separator . $content; 
            case 'APPEND': 
            default: 
                return $content . $separator . $markup; 
        } 
    } 
} 

该代码忘记了一个
getValues
函数。另外,请确保删除ViewHelper装饰器。 如果找不到元素,则需要将其添加到类路径中,然后

$this->addPrefixPath(
                     'Custom_Zend_Form_Element', 
                     'Custom/Zend/Form/Element', 
                     'element'
                   );

Thanx的答案。我测试了它,但我仍然得到这个错误:致命错误:找不到类“Custom\u Elements\u ArrayElement”
class My_Element_ArrayElement extends Zend_Form_Element 
{ 
    public function init() 
    { 
        $this->addPrefixPath('My_Decorator', 'My/Decorator/', 'decorator'); 
    } 

    public function setValue($value) 
    { 
        $this->_value = (array) $value; 
    } 

    public function getValues() 
    { 
        return $this->_value; 
    } 


    public function loadDefaultDecorators() 
    { 
        if ($this->loadDefaultDecoratorsIsDisabled()) { 
            return; 
        } 

        $decorators = $this->getDecorators(); 
        if (empty($decorators)) { 
            $this->addDecorator('ArrayElement'); 
        } 
    } 

} 

class My_Decorator_ArrayElement extends Zend_Form_Decorator_Abstract 
{ 
    public function render($content) 
    { 
        $element = $this->getElement(); 
        $view    = $element->getView(); 
        $markup  = ''; 
        $name    = $element->getName() . '[]'; 

        foreach ($element->getValues() as $value) { 
            $markup .= $view->formHidden($name, $value) . "\n"; 
        } 

        $separator = $this->getSeparator(); 
        switch ($this->getPlacement()) { 
            case 'PREPEND': 
                return $markup . $separator . $content; 
            case 'APPEND': 
            default: 
                return $content . $separator . $markup; 
        } 
    } 
} 
$this->addPrefixPath(
                     'Custom_Zend_Form_Element', 
                     'Custom/Zend/Form/Element', 
                     'element'
                   );