2016-05-09 3 views
2

Ich habe dieses Beispiel meine eigenen Formen anzupassen: http://framework.zend.com/manual/2.1/en/modules/zend.form.file-upload.htmlWarum gibt ZF2 PRG-Plugins zurück [fileUploadFileErrorFileNotFound] => Datei wurde nicht gefunden?

Wenn ich meine Datei mit Choose File Taste auf meiner Form hinzufügen und dann das Formular abzuschicken, erhalte ich dieses:

Array 
(
    [fileUploadFileErrorFileNotFound] => File was not found 
) 

und die Variable Inhalt davon ist das oben ausgedruckt ist dies (nach dem Formular einreichen):

$fileErrors = $form->get('character-ref')->getMessages(); 

Was kann das Problem sein? Ich habe zur Zeit keine Ahnung. Ich schaute auf RenameUpload Filter und ein paar Seiten, aber fehlt der Hinweis an dieser Stelle.

My-Code, wo relevant:

class CommissionInputFilter implements InputFilterAwareInterface 
{ 
    function getInputFilter() 
    { 
     $inputFilter = new InputFilter(); 

     //this is the filter that is supposed to make 
     //PRG Plugin file upload possible 
     $renameFilter = new RenameUpload(array(
      'target' => "./data/uploads/", 
      'randomize' => true 
     )); 

     // File Input - I am not sure if this is the way to do it 
     //some examples do not use FileInput 
     $fileInput = new FileInput('character-ref'); 
     $fileInput->setRequired(false); 
     $fileInput->getFilterChain()->attach($renameFilter); 
     $inputFilter->add($fileInput); 
     return $inputFilter; 
    } 
} 


//code inside controller 

public function addAction() 
{ 
    $form = new CommissionForm(); 
    $tempFile = null; 

    $prg = $this->fileprg($form); 

    if ($prg instanceof \Zend\Http\PhpEnvironment\Response) { 
     return $prg; 
    } elseif (is_array($prg)) { 

     //************************************************** 
     //this line below is where I set my input filter for the form 
     //the filter that contains PRG Rename pluging supposedly 
     //One interesting note is if I *Remove* the line below 
     //then the PRG Plugin keeps the file name as it is supposed to 
     //************************************************** 

     $form->setInputFilter((new CommissionInputFilter())->getInputFilter()); 
     if ($form->isValid()) { 

      $output = new CommissionOutput(); 

      $commission = $output->getCommission($form->getData()); 
      $id = $this->repository->saveCommission($commission); 

      $view = new ViewModel(); 
      $view->setTemplate('commission/commission/thank_you'); 
      $view->setVariables($prg); 
      return $view; 
     } else { 

      //******************************************************** 
      //My Properly-filled out form ends up here with file errors 
      //******************************************************** 

      $fileErrors = $form->get('character-ref')->getMessages(); 
      if (empty($fileErrors)) { 
       $tempFile = $form->get('character-ref')->getValue(); 
      } 
     } 
    } 
    return array(
     'form' => $form, 
     'characterRefFile' => $tempFile 
    ); 
} 

Antwort

0

Oh Nun, ich denke Entsendung darüber hilft.

Weil ich die Ursache gefunden habe. Offenbar

  1. Das Formular ein Formular Filter muss richtig eingestellt [getan]
  2. PRG RenameUpload Filter einrichten muss [getan]
  3. Am wichtigsten ist, muss das Formular Filter nach Formularerstellung eingerichtet werden und vor PRG [nicht getan]
$inputFilter = (new CommissionInputFilter())->getInputFilter(); 

$form = new CommissionForm(); 
$form->setInputFilter($inputFilter); 
$prg = $this->fileprg($form); 

Filterung nach Formularerstellung eingerichtet werden muss und vor dem PRG-Plugin yay.

Verwandte Themen