From d63409660662ae8f9fb5f5f527d194a145928a3e Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 15 Jan 2025 16:53:35 +0300 Subject: [PATCH] =?utf8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=20=D1=81=D0=BE?= =?utf8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=B3?= =?utf8?q?=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B9=20=D1=81=D1=82=D1=80=D0=B0?= =?utf8?q?=D0=BD=D0=B8=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/StoresTypeListController.php | 24 +++++++----- erp24/records/StoresTypeList.php | 3 +- erp24/views/stores-type-list/index.php | 38 +++++++++++++++---- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/erp24/controllers/StoresTypeListController.php b/erp24/controllers/StoresTypeListController.php index 02e5b985..aaf8a04d 100644 --- a/erp24/controllers/StoresTypeListController.php +++ b/erp24/controllers/StoresTypeListController.php @@ -2,6 +2,7 @@ namespace app\controllers; +use Yii; use yii\data\ActiveDataProvider; use yii\filters\VerbFilter; use yii\web\Controller; @@ -38,22 +39,25 @@ class StoresTypeListController extends Controller */ public function actionIndex() { + $model = new StoresTypeList(); + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->validate()) { + $model->type_alias = strtolower(preg_replace('/[\s-]+/', '_', $model->type_name)); + + if ($model->save()) { + Yii::$app->session->setFlash('success', 'Тип магазина успешно сохранен.'); + return $this->redirect(['index']); + } + } + } + $dataProvider = new ActiveDataProvider([ 'query' => StoresTypeList::find(), - /* - 'pagination' => [ - 'pageSize' => 50 - ], - 'sort' => [ - 'defaultOrder' => [ - 'id' => SORT_DESC, - ] - ], - */ ]); return $this->render('index', [ 'dataProvider' => $dataProvider, + 'model' => $model, ]); } diff --git a/erp24/records/StoresTypeList.php b/erp24/records/StoresTypeList.php index ceab1b50..1955e758 100644 --- a/erp24/records/StoresTypeList.php +++ b/erp24/records/StoresTypeList.php @@ -29,8 +29,9 @@ class StoresTypeList extends \yii\db\ActiveRecord public function rules() { return [ - [['type_name', 'type_alias'], 'required'], + [['type_name'], 'required'], [['created_at'], 'safe'], + [['type_name'], 'unique', 'message' => 'Название "{value}" уже существует.'], [['type_name', 'type_alias', 'type_description'], 'string', 'max' => 255], ]; } diff --git a/erp24/views/stores-type-list/index.php b/erp24/views/stores-type-list/index.php index fe65d02d..a7de5094 100644 --- a/erp24/views/stores-type-list/index.php +++ b/erp24/views/stores-type-list/index.php @@ -1,13 +1,16 @@ title = 'Тип магазина'; $this->params['breadcrumbs'][] = $this->title; @@ -16,10 +19,29 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

-

- 'btn btn-success']) ?> -

+ false]); ?> + session->hasFlash('success')): ?> +
+ session->getFlash('success') ?> +
+ + session->hasFlash('error')): ?> +
+ session->getFlash('error') ?> +
+ +
+ ['data-pjax' => true], + ]); ?> + + field($model, 'type_name')->textInput(['maxlength' => true])->label('Название типа') ?> + + 'btn btn-success']) ?> + + +
$dataProvider, @@ -33,12 +55,12 @@ $this->params['breadcrumbs'][] = $this->title; 'created_at', [ 'class' => ActionColumn::class, - 'urlCreator' => function ($action, StoresTypeList $model, $key, $index, $column) { + 'urlCreator' => function ($action, $model, $key, $index, $column) { return Url::toRoute([$action, 'id' => $model->id]); - } + }, ], ], ]); ?> - + -- 2.39.5