<?php

namespace backend\controllers;

use backend\models\Frapl011a;
use backend\models\Frapl011aSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

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

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

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

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

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

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

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

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

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

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

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

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

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

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