[ '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(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->validate()) { //CustomVarDamp::dumpAndDie(Yii::$app->request->post()); $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), 200 ); $provider = new ArrayDataProvider([ 'allModels' => $data, 'pagination' => [ 'pageSize' => 10, ], // 'sort' => [ // 'attributes' => ['id', 'name'], // ], ]); return $this->render('results', ['model' => $data, 'imp' => $model, 'dataProvider' => $provider]); } } 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, ], // 'sort' => [ // 'attributes' => ['id', 'name'], // ], ]); return $this->render('results', ['model' => $data, 'imp' => $model, 'dataProvider' => $provider]); } return $this->render('index', ['model' => $model]); } public function actionWrite() { CustomVarDamp::dumpAndDie(Yii::$app->request->post()); } }