<?php

namespace backend\controllers;

use backend\models\Frapl02;
use backend\models\Frapl02Search;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

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

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

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

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

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

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

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

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

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

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

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

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

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

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