From: fomichev Date: Wed, 15 Jan 2025 13:53:35 +0000 (+0300) Subject: Форма создания на главной странице X-Git-Tag: 1.7~57^2~5 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d63409660662ae8f9fb5f5f527d194a145928a3e;p=erp24_rep%2Fyii-erp24%2F.git Форма создания на главной странице --- 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]); - } + }, ], ], ]); ?> - +