3 namespace app\controllers;
6 use app\models\Regions;
7 use app\models\RegionsSearch;
8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter;
13 * RegionsController implements the CRUD actions for Regions model.
15 class RegionsController extends Controller
20 public function behaviors()
24 'class' => VerbFilter::className(),
33 * Список всех регионов/подразделений.
36 public function actionIndex()
38 $searchModel = new RegionsSearch();
39 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
41 return $this->render('index', [
42 'searchModel' => $searchModel,
43 'dataProvider' => $dataProvider,
48 * Плказ одного региона/подразделения (не используется).
51 * @throws NotFoundHttpException если отсутствует регион/подразделение
53 public function actionView($id)
55 return $this->render('view', [
56 'model' => $this->findModel($id),
61 * Создание нового региона/подразделения.
62 * В случае успешного создания региона/подразделения, происходит переход к списку всех регионов/подразделений.
65 public function actionCreate()
67 $model = new Regions();
69 if ($model->load(Yii::$app->request->post()) && $model->save()) {
70 return $this->redirect(['index', 'id' => $model->id]);
73 return $this->render('create', [
79 * Изменение существующего региона/подразделения.
80 * В случае успешного редактирования, происходит переход к списку всех ергионов/подразделений.
83 * @throws NotFoundHttpException если отсутствует регион/подразделение
85 public function actionUpdate($id)
87 $model = $this->findModel($id);
89 if ($model->load(Yii::$app->request->post()) && $model->save()) {
90 return $this->redirect(['index', 'id' => $model->id]);
93 return $this->render('update', [
99 * Удаление существующего региона/подразделения.
100 * В случае успешного удаления, происходит переход к списку всех регоинов/подразделений.
103 * @throws NotFoundHttpException если отсутсвует регион/подразделение
105 public function actionDelete($id)
107 $this->findModel($id)->delete();
109 return $this->redirect(['index']);
113 * Finds the Regions model based on its primary key value.
114 * If the model is not found, a 404 HTTP exception will be thrown.
116 * @return Regions the loaded model
117 * @throws NotFoundHttpException if the model cannot be found
119 protected function findModel($id)
121 if (($model = Regions::findOne($id)) !== null) {
125 throw new NotFoundHttpException(Yii::t('regions', 'The requested page does not exist.'));