2011-10-19 45 views
1

嗨我有我的自定义zend_form文件元素的问题。这就是代码:自定义Zend表格装饰器文件没有找到

class Core_Form extends Zend_Form 
{ 


protected $_containerId; 
public function __construct($options = null) { 
    parent::__construct($options); 

    $this->setElementDecorators(array(
     'ViewHelper', 
     array(
      'Description', 
      array(
       'tag' => 'div', 
       'class' => 'submit-button', 
       'escape' => false 
      ) 
     ), 
     array(
      array(
       'data' => 'HtmlTag' 
      ), 
      array(
       'tag' => 'div', 
       'class' => 'element' 
      ) 
     ), 
     array(
      'Label', 
      array(
       'tag' => 'div', 
       'escape' => false 
      ) 
     ), 
     array(
      array(
       'row' => 'HtmlTag' 
      ), 
      array(
       'tag' => 'div', 
       'class' => 'element-row' 
      ), 
     ), 
     'Errors' 
    )); 

    $this->setDecorators(array(
     'FormElements', 
     array(
      'HtmlTag', 
      array(
       'tag' => 'div', 
       'id' => $this->_containerId 
      ) 
     ), 
     'Form', 
     'Errors' 
    )); 
} 
} 
//upload form 
class Upload_Form extends Core_Form 
{ 

public function init() 
{ 
    /* Form Elements & Other Definitions Here ... */ 

    $this->addElement('file', 'uploadFile', array(
     'destination' => APPLICATION_PATH.'/../public/uploads/ads', 
     'validators' => array(
      array('count', false, 1), 
      array('size', false, 102400), 
     ), 
     'label' => 'Wyślij plik:' 
    )); 

    $this->addElement('image', 'submit', array(
     'label' => false, 
     'ignore' => true, 
     'src' => $this->getView()->baseUrl('images/send.jpg') 
    )); 

    $this->setEnctype('multipart/form-data'); 
} 

} 

我收到此错误: 警告:异常的形式捕获:没有文件装饰发现...无法呈现文件元素

当我改变我的视图助手的元素装饰为'文件”我收到此错误: 警告:异常的形式捕获:方法getMaxFileSize不存在堆栈跟踪:#0内部功能]:Zend_Form_Element的 - > __通话(‘getMaxFileSize’,阵列)

感谢您提前你的帮助

回答

2

您需要为File元素设置一组不同的修饰器,它需要使用'File'修饰器。

你可以看到一个非常类似的问题在这里:How do I use ViewScripts on Zend_Form File Elements?

希望帮助,

+0

你好谢谢回答!是的,它使我有可能使其工作,但它不完全如何我想解决这个问题...我想在Core_Form定义中设置我的装饰器...有了这个解决方案,我必须得到每一次'上传'元素和setdecorators ...有没有什么办法可以在基本核心表单定义中设置我的装饰器,使其每次像原来的Zend_Form一样工作? – JokerDark2

+0

您可以在添加表单后循环遍历表单的所有元素,并根据元素类型选择一种装饰器。这不是一个不合理的解决方案。 – dinopmi