pia-sophie
pia-sophie

Reputation: 505

column missing in exchangearray

I'm missing a column in my exchangeArray. It is the column with the filename, here a snippet of my controller add action:

if ($form->isValid()) {
                    $data = $form->getData();
                    // Upload path

                    $location = "public/files/";
                    // A bit validation of uploaded file
                    $allowedExtension = array('xls', 'xlsx');
                    $extension = explode('.', $data['DCL_Path']['name']);
                    $extension = end($extension);
                    $import['DCL_Path']=$data['DCL_Path']['name'];
                    //$fileName = time() . '.' . $extension;
                    $fileName = $data['DCL_Path']['name'];
                    // Check if everything is OK!
                    //echo $fileName;
                    if (0 === $data['DCL_Path']['error'] && in_array($extension, $allowedExtension)) {
                        move_uploaded_file($data['DCL_Path']['tmp_name'], $location . $fileName);
                    } else {
                        echo 'Something went wrong!';
                    }


                    //$namen = explode(",", $import ); //Konvertierung des Strings in ein Array
                    //echo "<pre>"; var_dump($namen); echo "</pre>"; //Formartierte Ausgabe des Arrays
                    $this->table->saveImport($import);      

Everything will be saved, but DCL_path is missing.

Here my exchangearray also:

public function exchangeArray(array $data)
{
    $this->DCLID= !empty($data['DCLID']) ? $data['DCLID'] : null;
    $this->UnitID= !empty($data['UnitID']) ? $data['UnitID'] : null;
    $this->DCL_Path= !empty($data['DCL_Path']) ? $data['DCL_Path'] : null;
    $this->Importdate= !empty($data['Importdate']) ? $data['Importdate'] : null;
    $this->Importuser= !empty($data['Importuser']) ? $data['Importuser'] : null;
    $this->Importok= !empty($data['Importok']) ? $data['Importok'] : null;
    $this->DCL_Type= !empty($data['DCL_Type']) ? $data['DCL_Type'] : null;
    $this->Changed_per_User= !empty($data['Changed_per_User']) ? $data['Changed_per_User'] : null;
    $this->Description_Changes= !empty($data['Description_Changes']) ? $data['Description_Changes'] : null;
}

I added this statement: $import['DCL_Path']=$data['DCL_Path']['name']; to force it, but it didn't help. So my question would be how to add data in datafields of my exchangeArray.

EDIT1: Here is the start off my addAction.

$import = new Import();     //Neue Instanz von Import
        $form->setInputFilter($import->getInputFilter());       //Filter an Form binden
        $form->setData($request->getPost());        //Daten abholen
        //echo $form->isValid();
        if (! $form->isValid()) {
            return ['form' => $form];       //Wenn die Daten nicht valide sind
        //  return $this->redirect()->toRoute('import');        //Routing
        //  Zend_Debug::dump("nicht valide");
            //echo "nicht valide";
        }   
        else{           //aus Tableadapter
                $import->exchangeArray($form->getData());
        //      echo "valide";
                //echo $import["DCL_Path"];
                // Merge data thus
                $data = array_merge_recursive(
                        $this->getRequest()->getPost()->toArray(),
                        $this->getRequest()->getFiles()->toArray()
                        );
                $form->setData($data);

I also find another solution which is working, I post it additional perhaps it might help somebody else. Of course I still would prefer the way via exchangeArray.

$this->table->saveImport($import);                  //Daten speichern
                    $letzter = $this->table->getlastImport($fileName);
                    echo ($letzter->DCLID);
                    $this->table->updateoneRow($letzter->DCLID, 'DCL_Path', $fileName);

Upvotes: 0

Views: 30

Answers (0)

Related Questions