在exchangearray中缺少列

时间:2017-06-29 08:52:20

标签: zend-framework zend-db zend-framework3

我在exchangeArray中遗漏了一栏。它是带有文件名的列,这里是我的控制器添加动作的片段:

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);      

将保存所有内容,但缺少DCL_path。

这里我的交换阵列也是:

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;
}

我添加了这句话:$import['DCL_Path']=$data['DCL_Path']['name'];强迫它,但它没有帮助。所以我的问题是如何在exchangeArray的数据字段中添加数据。

EDIT1:这是我的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);

我还找到了另一种有效的解决方案,我发布它可能会对其他人有所帮助。当然我还是喜欢通过exchangeArray的方式。

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

0 个答案:

没有答案