[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['index','results','write'], '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 UploadFileParsingForm(); return $this->render('index', ['model' => $model]); } public function actionResults(){ $model = new UploadFileParsingForm(); $data = []; if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->validate()) { $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; $model->file->saveAs( $filePath ); $data = $model->readFile($filePath); Yii::$app->getCache()->set( 'parser_data', json_encode($data) ); } } else if( Yii::$app->getCache()->get( 'parser_data' )) { $data = json_decode( Yii::$app->getCache()->get( 'parser_data' ),true ); } $provider = new ArrayDataProvider([ 'allModels' => $data, 'pagination' => [ 'pageSize' => 10, ], ]); // CustomVarDamp::dumpAndDie($data); $header_model = DynamicFormHelper::CreateDynamicModel( count( $data[0] ) ); // CustomVarDamp::dumpAndDie(Yii::$app->multiparser->getConfiguration('csv','basic_column')); return $this->render('results', ['model' => $data, 'header_model' => $header_model, 'basic_column' => Yii::$app->multiparser->getConfiguration('csv','basic_column'), 'dataProvider' => $provider]); } public function actionWrite() { //CustomVarDamp::dumpAndDie(Yii::$app->request->post()); $arr_attributes = Yii::$app->request->post()['DynamicModel']; $model = DynamicFormHelper::CreateDynamicModel( $arr_attributes ); foreach ($arr_attributes as $key => $value) { $model->addRule($key, 'in', ['range' => array_keys( Yii::$app->multiparser->getConfiguration('csv','basic_column') )]); } //CustomVarDamp::dumpAndDie($model); if ($model->validate()) { $arr = $model->toArray(); CustomVarDamp::dumpAndDie($arr); } } }