Zend framework 如何预填充zend文件元素

Zend framework 如何预填充zend文件元素,zend-framework,Zend Framework,我有这样一个Zend表格: $this->setName('Add Job'); $id = new Zend_Form_Element_Hidden('id'); $id->addFilter('Int'); $name = new Zend_Form_Element_Text('name'); $name->setLabel('Name') ->setRequired(true) ->addFilter('StripTags'

我有这样一个Zend表格:

     $this->setName('Add Job');
  $id = new Zend_Form_Element_Hidden('id');
  $id->addFilter('Int');

  $name = new Zend_Form_Element_Text('name');
  $name->setLabel('Name')
  ->setRequired(true)
  ->addFilter('StripTags')
  ->addFilter('StringTrim')
  ->addValidator('NotEmpty'); 

  $file = new Zend_Form_Element_File('file');
  $file->setLabel('File')
  ->setRequired(true);

  $category = new Zend_Form_Element_Checkbox('category');
  $category->setLabel('Express?')
  ->setRequired(true)
  ->setCheckedValue('2')
  ->setUncheckedValue('1');   

  $submit = new Zend_Form_Element_Submit('submit');
  $submit->setAttrib('id', 'submitbutton');
“添加”操作工作正常,但我没有在控制器中使用此操作来执行“编辑”操作:

 $id = $this->_getParam('id', 0);    
 if ($id > 0) {
      $jobs = new Application_Model_DbTable_Jobs();
      $form->populate($jobs->getJob($id));
 }
除file元素外,表单预填充得很好。在DB中,我保存了文件名,我想以某种方式将其显示在编辑表单中-Zend中是否有处理此问题的标准方法

谢谢


菲尔

您不能预先填充文件输入元素。

这不是Zend_形式的限制。html输入文件元素没有“value”属性。

您无法预先填充文件输入元素。

这不是Zend_形式的限制。html输入文件元素没有“value”属性。

我使用了一个技巧,将文件名传递给视图,这样就可以在上载旁边显示图像。在表单中键入以下内容:

$this->getElement('image')->setAttrib('class', $this->_myParams['data']['image']);
$image->setDecorators(array(
            'File',
            array('ViewScript', array('viewScript' => '/ditta/_image.phtml', 'placement' => false)))
        );/
然后在viewscript中使用

$image = $this->element->getAttrib('class');//get name of file
$this->element->setAttrib('class', '');//delete class

我使用了一个技巧,将文件名传递给视图,这样就可以在上传旁边显示图像。在表单中键入以下内容:

$this->getElement('image')->setAttrib('class', $this->_myParams['data']['image']);
$image->setDecorators(array(
            'File',
            array('ViewScript', array('viewScript' => '/ditta/_image.phtml', 'placement' => false)))
        );/
然后在viewscript中使用

$image = $this->element->getAttrib('class');//get name of file
$this->element->setAttrib('class', '');//delete class