[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['index'], '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(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file && $model->validate()) { $filePath = Yii::getAlias('@webroot') . '/uploads/' . $model->file->baseName . '.' . $model->file->extension; $model->file->saveAs( $filePath ); $parser = new ParserHandler( $filePath, $model ); $data = $parser->run(); if( !is_array($data) ){ $data = ['No results']; } $provider = new ArrayDataProvider([ 'allModels' => $data, 'pagination' => [ 'pageSize' => 10, ], // 'sort' => [ // 'attributes' => ['id', 'name'], // ], ]); return $this->render('results', ['model' => $data, 'dataProvider' => $provider]); } } return $this->render('index', ['model' => $model]); } }