[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['index', 'result'], 'allow' => true, 'roles' => ['@'], ], ], ], // 'verbs' => [ // 'class' => VerbFilter::className(), // 'actions' => [ // 'logout' => ['post'], // ], // ], ]; } /** * @inheritdoc */ public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], ]; } public function actionIndex() { $model = new UploadFileCrossingForm(); return $this->render('index', ['model' => $model]); } public function actionResult() { $model = new UploadFileCrossingForm(); $data = []; if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->validate()) { $file_name = $model->file->name; $model->file_path = Yii::getAlias('@temp_upload') . '/' . $file_name; $model->file->saveAs($model->file_path); //запускаем парсинг // доп. опции для парсера - удаление префикса в артикулах $options['mode'] = 'crosses'; $fields = []; if ($model->delete_prefix1) { $fields[] = 'ARTICLE'; } if ($model->delete_prefix2) { $fields[] = 'CROSS_ARTICLE'; } if ( $fields ) { $options [ 'converter_conf' ] = [ 'configuration' => [ "article" => $fields , "string" => ['ARTICLE', 'CROSS_ARTICLE'],] ]; } else { $options [ 'converter_conf' ] = [ 'configuration' => [ "string" => ['ARTICLE', 'CROSS_ARTICLE'], ] ]; } $data = $model->readFile( $options ); $crosses_model = new DetailsCrosses(); $crosses_model->ManualInsertWithIgnore( $data ); Yii::$app->session->setFlash('success', 'Файл кроссов успешно загружен'); return $this->render('index', ['model' => $model]); }else{ // не прошла валидация форма загрузки файлов $errors_str = ''; foreach ($model->getErrors() as $error) { $errors_str .= implode( array_values($error) ); } throw new \ErrorException( $errors_str ); } } else { throw new \ErrorException( 'Ошибка загрузки данных' ); } } }