guild/backend/modules/settings/controllers/SkillController.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\Skill;
use backend\modules\settings\models\SkillSearch;
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
* SkillController implements the CRUD actions for Skill model.
2018-10-11 11:15:09 +03:00
*/
2018-10-12 14:52:08 +03:00
class SkillController extends Controller
2018-10-11 11:15:09 +03:00
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
2018-10-12 14:52:08 +03:00
* Lists all Skill models.
2018-10-11 11:15:09 +03:00
* @return mixed
*/
public function actionIndex()
{
2018-10-12 14:52:08 +03:00
$searchModel = new SkillSearch();
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 Skill 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 Skill 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 Skill();
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 Skill 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 Skill 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 Skill 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 Skill 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 = Skill::findOne($id)) !== null) {
2018-10-11 11:15:09 +03:00
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}