<?php

namespace backend\controllers;

use backend\models\Frapl013a;
use backend\models\Frapl013aSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * Frapl013aController implements the CRUD actions for Frapl013a model.
 */
class Frapl013aController extends Controller
{
    /**
     * @inheritDoc
     */
    public function behaviors()
    {
        return array_merge(
            parent::behaviors(),
            [
                'verbs' => [
                    'class' => VerbFilter::className(),
                    'actions' => [
                        'delete' => ['POST'],
                    ],
                ],
            ]
        );
    }

    /**
     * Lists all Frapl013a models.
     *
     * @return string
     */
    public function actionIndex()
    {
        $searchModel = new Frapl013aSearch();
        $dataProvider = $searchModel->search($this->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Frapl013a model.
     * @param string $FRAPL01_3A_UUID Frapl01 3a Uuid
     * @return string
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($FRAPL01_3A_UUID)
    {
        return $this->render('view', [
            'model' => $this->findModel($FRAPL01_3A_UUID),
        ]);
    }

    /**
     * Creates a new Frapl013a model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return string|\yii\web\Response
     */
    public function actionCreate()
    {
        $model = new Frapl013a();

        if ($this->request->isPost) {
            if ($model->load($this->request->post()) && $model->save()) {
                return $this->redirect(['view', 'FRAPL01_3A_UUID' => $model->FRAPL01_3A_UUID]);
            }
        } else {
            $model->loadDefaultValues();
        }

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

    /**
     * Updates an existing Frapl013a model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $FRAPL01_3A_UUID Frapl01 3a Uuid
     * @return string|\yii\web\Response
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($FRAPL01_3A_UUID)
    {
        $model = $this->findModel($FRAPL01_3A_UUID);

        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
            return $this->redirect(['view', 'FRAPL01_3A_UUID' => $model->FRAPL01_3A_UUID]);
        }

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

    /**
     * Deletes an existing Frapl013a model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $FRAPL01_3A_UUID Frapl01 3a Uuid
     * @return \yii\web\Response
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($FRAPL01_3A_UUID)
    {
        $this->findModel($FRAPL01_3A_UUID)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the Frapl013a model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $FRAPL01_3A_UUID Frapl01 3a Uuid
     * @return Frapl013a the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($FRAPL01_3A_UUID)
    {
        if (($model = Frapl013a::findOne(['FRAPL01_3A_UUID' => $FRAPL01_3A_UUID])) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }
}
