Zend 文件上传和元素装饰器
我遇到问题,以下 Zend Form 抛出错误。 问题是“文件”元素和使用 setElementDecorators。
class Products_AddForm extends Zend_Form
{
function init() {
// other form elements...
$uploadElement = new Zend_Form_Element_File('Excel');
$uploadElement->setLabel('Excel');
$this->addElement($uploadElement);
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'th')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
}
}
这会引发错误。
(Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 )
在 SetElementDecorators
之后添加 $uploadElement->addDecorator('File');
将会起作用,但这会给我两次文件元素!
有人可以帮忙吗?
TIA 马特
I have the problem, that the following Zend Form throws an error.
The problem is the "file"-element and using setElementDecorators.
class Products_AddForm extends Zend_Form
{
function init() {
// other form elements...
$uploadElement = new Zend_Form_Element_File('Excel');
$uploadElement->setLabel('Excel');
$this->addElement($uploadElement);
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'th')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
}
}
This throws an error.
(Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 )
Adding $uploadElement->addDecorator('File');
at the end after the SetElementDecorators
will work, but this will give me the file element twice!
Can anybody help, please?
TIA
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
File 元素需要它自己的装饰器 - Zend_Form_Decorator_File。
[编辑]
刚刚注意到您还在使用其他表单元素。
在原始代码之后添加:
这样,ViewHelper 就会添加到所有其他元素,并且对于您的 File 元素,将使用 File 代替。
The File element requires it's own decorator - Zend_Form_Decorator_File.
[edit]
Have just noticed that you are also using other form elements.
After your original code, add:
That way, ViewHelper is added to all other elements, and for your File element File is used instead.