I
I
ITwoolf2019-03-22 10:09:19
Yii
ITwoolf, 2019-03-22 10:09:19

How to change line type when uploading files?

Hello. I want to load the table that I exported. Writes that the type of the id_avtor1 string must be integer (Array ( [id_avtor1] => Array ( [0] => Id Avtor1 must be an integer). Changed from int to integer in models. But, it turns out, you need to change it in the controller when How to change the type of the id_avtor1 field to integer here?

public function actionUpload()
    {

        $model = new UploadForm();
        if (Yii::$app->request->isPost ) {
            $model->fName = UploadedFile::getInstance($model, 'fName');
            if ($fName =$model->upload()) {
                    //путь к файлу

                    if (($handle = fopen($fName, 'r')) !== false) {


                        while (($row = fgetcsv($handle, 1000, ',')) !== false) {
                            $model = new Kniga1();
                            $model->name = $row [0];
                            $model->creation_date = $row [1];
                            $model->id_avtor1 = $row [2];

                            if ($model->validate()) {
                                $model->save();
                            } else {
                                $model->save();
                                print_r($model->errors);
                            }
                        }
                        fclose($handle);
                    };
                    //... код после импорта
            }

        }
        return $this->render('upload', ['model' => $model]);
    }

I tried the option but it's not that) $model->id_avtor1='integer';

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question