guild/backend/modules/settings/controllers/PositionController.php

128 lines
3.2 KiB
PHP
Raw Normal View History

2018-10-11 11:15:09 +03:00
<?php
2018-10-12 14:52:08 +03:00
namespace backend\modules\settings\controllers;
2018-10-11 11:15:09 +03:00
use Yii;
2018-10-12 14:52:08 +03:00
use backend\modules\settings\models\Position;
use backend\modules\settings\models\PositionSearch;
2018-10-11 11:15:09 +03:00
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
2018-10-12 14:52:08 +03:00
* PositionController implements the CRUD actions for Position model.
2018-10-11 11:15:09 +03:00
*/
2018-10-12 14:52:08 +03:00
class PositionController extends Controller
2018-10-11 11:15:09 +03:00
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
2018-10-12 14:52:08 +03:00
'class' => VerbFilter::class,
2018-10-11 11:15:09 +03:00
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
2018-10-12 14:52:08 +03:00
* Lists all Position models.
2018-10-11 11:15:09 +03:00
* @return mixed
*/
public function actionIndex()
{
2018-10-12 14:52:08 +03:00
$searchModel = new PositionSearch();
2018-10-11 11:15:09 +03:00
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
2018-10-12 14:52:08 +03:00
* Displays a single Position model.
2018-10-11 11:15:09 +03:00
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
2018-10-12 14:52:08 +03:00
* Creates a new Position model.
2018-10-11 11:15:09 +03:00
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
2018-10-12 14:52:08 +03:00
$model = new Position();
2018-10-11 11:15:09 +03:00
if ($model->load(Yii::$app->request->post()) && $model->save()) {
2018-10-11 17:24:47 +03:00
return $this->redirect(['index']);
2018-10-11 11:15:09 +03:00
}
return $this->render('create', [
'model' => $model,
]);
}
/**
2018-10-12 14:52:08 +03:00
* Updates an existing Position model.
2018-10-11 11:15:09 +03:00
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
2018-10-11 17:24:47 +03:00
return $this->redirect(['index']);
2018-10-11 11:15:09 +03:00
}
2018-10-12 14:52:08 +03:00
2018-10-11 11:15:09 +03:00
return $this->render('update', [
'model' => $model,
]);
}
/**
2018-10-12 14:52:08 +03:00
* Deletes an existing Position model.
2018-10-11 11:15:09 +03:00
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
2018-10-12 14:52:08 +03:00
* Finds the Position model based on its primary key value.
2018-10-11 11:15:09 +03:00
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
2018-10-12 14:52:08 +03:00
* @return Position the loaded model
2018-10-11 11:15:09 +03:00
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
2018-10-12 14:52:08 +03:00
if (($model = Position::findOne($id)) !== null) {
2018-10-11 11:15:09 +03:00
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}