]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Создание базового crud
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 15 Jan 2025 12:55:12 +0000 (15:55 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 15 Jan 2025 12:55:12 +0000 (15:55 +0300)
erp24/controllers/StoresTypeListController.php [new file with mode: 0644]
erp24/migrations/m250115_114940_create_stores_type_list_table.php [new file with mode: 0644]
erp24/records/StoresTypeList.php [new file with mode: 0644]
erp24/views/stores-type-list/_form.php [new file with mode: 0644]
erp24/views/stores-type-list/create.php [new file with mode: 0644]
erp24/views/stores-type-list/index.php [new file with mode: 0644]
erp24/views/stores-type-list/update.php [new file with mode: 0644]
erp24/views/stores-type-list/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/StoresTypeListController.php b/erp24/controllers/StoresTypeListController.php
new file mode 100644 (file)
index 0000000..02e5b98
--- /dev/null
@@ -0,0 +1,144 @@
+<?php
+
+namespace app\controllers;
+
+use yii\data\ActiveDataProvider;
+use yii\filters\VerbFilter;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii_app\records\StoresTypeList;
+
+/**
+ * StoresTypeListController implements the CRUD actions for StoresTypeList model.
+ */
+class StoresTypeListController extends Controller
+{
+    /**
+     * @inheritDoc
+     */
+    public function behaviors()
+    {
+        return array_merge(
+            parent::behaviors(),
+            [
+                'verbs' => [
+                    'class' => VerbFilter::class,
+                    'actions' => [
+                        'delete' => ['POST'],
+                    ],
+                ],
+            ]
+        );
+    }
+
+    /**
+     * Lists all StoresTypeList models.
+     *
+     * @return string
+     */
+    public function actionIndex()
+    {
+        $dataProvider = new ActiveDataProvider([
+            'query' => StoresTypeList::find(),
+            /*
+            'pagination' => [
+                'pageSize' => 50
+            ],
+            'sort' => [
+                'defaultOrder' => [
+                    'id' => SORT_DESC,
+                ]
+            ],
+            */
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
+
+    /**
+     * Displays a single StoresTypeList model.
+     * @param int $id ID
+     * @return string
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionView($id)
+    {
+        return $this->render('view', [
+            'model' => $this->findModel($id),
+        ]);
+    }
+
+    /**
+     * Creates a new StoresTypeList model.
+     * If creation is successful, the browser will be redirected to the 'view' page.
+     * @return string|\yii\web\Response
+     */
+    public function actionCreate()
+    {
+        $model = new StoresTypeList();
+
+        if ($this->request->isPost) {
+            if ($model->load($this->request->post()) && $model->save()) {
+                return $this->redirect(['view', 'id' => $model->id]);
+            }
+        } else {
+            $model->loadDefaultValues();
+        }
+
+        return $this->render('create', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Updates an existing StoresTypeList model.
+     * If update is successful, the browser will be redirected to the 'view' page.
+     * @param int $id ID
+     * @return string|\yii\web\Response
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionUpdate($id)
+    {
+        $model = $this->findModel($id);
+
+        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('update', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Deletes an existing StoresTypeList model.
+     * If deletion is successful, the browser will be redirected to the 'index' page.
+     * @param int $id ID
+     * @return \yii\web\Response
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    public function actionDelete($id)
+    {
+        $this->findModel($id)->delete();
+
+        return $this->redirect(['index']);
+    }
+
+    /**
+     * Finds the StoresTypeList model based on its primary key value.
+     * If the model is not found, a 404 HTTP exception will be thrown.
+     * @param int $id ID
+     * @return StoresTypeList the loaded model
+     * @throws NotFoundHttpException if the model cannot be found
+     */
+    protected function findModel($id)
+    {
+        if (($model = StoresTypeList::findOne(['id' => $id])) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
diff --git a/erp24/migrations/m250115_114940_create_stores_type_list_table.php b/erp24/migrations/m250115_114940_create_stores_type_list_table.php
new file mode 100644 (file)
index 0000000..4ad1b41
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%stores_type_list}}`.
+ */
+class m250115_114940_create_stores_type_list_table extends Migration
+{
+    const TABLE_NAME = 'erp24.stores_type_list';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+        if (!isset($tableSchema)) {
+            $this->createTable(self::TABLE_NAME, [
+                'id' => $this->bigPrimaryKey()->comment('ID'),
+                'type_name' => $this->string()->notNull()->comment('Наименование типа магазина'),
+                'type_alias' => $this->string()->notNull()->comment('Алиас типа магазина'),
+                'type_description' => $this->string()->null()->comment('Описание типа магазина'),
+                'created_at' => $this->dateTime()
+                    ->notNull()
+                    ->defaultExpression('CURRENT_TIMESTAMP')
+                    ->comment('Дата создания записи'),
+            ]);
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+        if (isset($tableSchema)) {
+            $this->dropTable(self::TABLE_NAME);
+        }
+    }
+}
diff --git a/erp24/records/StoresTypeList.php b/erp24/records/StoresTypeList.php
new file mode 100644 (file)
index 0000000..ceab1b5
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "stores_type_list".
+ *
+ * @property int $id ID
+ * @property string $type_name Наименование типа магазина
+ * @property string $type_alias Алиас типа магазина
+ * @property string|null $type_description Описание типа магазина
+ * @property string $created_at Дата создания записи
+ */
+class StoresTypeList extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'stores_type_list';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['type_name', 'type_alias'], 'required'],
+            [['created_at'], 'safe'],
+            [['type_name', 'type_alias', 'type_description'], 'string', 'max' => 255],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'type_name' => 'Наименование типа магазина',
+            'type_alias' => 'Алиас типа магазина',
+            'type_description' => 'Описание типа магазина',
+            'created_at' => 'Дата создания записи',
+        ];
+    }
+}
diff --git a/erp24/views/stores-type-list/_form.php b/erp24/views/stores-type-list/_form.php
new file mode 100644 (file)
index 0000000..e22d2a2
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\StoresTypeList $model */
+/** @var yii\widgets\ActiveForm $form */
+?>
+
+<div class="stores-type-list-form">
+
+    <?php $form = ActiveForm::begin(); ?>
+
+    <?= $form->field($model, 'type_name')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'type_alias')->textInput(['maxlength' => true]) ?>
+
+    <?= $form->field($model, 'type_description')->textInput(['maxlength' => true]) ?>
+
+
+    <div class="form-group">
+        <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+
+</div>
diff --git a/erp24/views/stores-type-list/create.php b/erp24/views/stores-type-list/create.php
new file mode 100644 (file)
index 0000000..c5d59b2
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\StoresTypeList $model */
+
+$this->title = 'Создание типа магазина';
+$this->params['breadcrumbs'][] = ['label' => 'Stores Type Lists', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="stores-type-list-create p-4">
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary m-5']) ?>
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/stores-type-list/index.php b/erp24/views/stores-type-list/index.php
new file mode 100644 (file)
index 0000000..fe65d02
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+use yii_app\records\StoresTypeList;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Тип магазина';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="stores-type-list-index p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            'id',
+            'type_name',
+            'type_alias',
+            'type_description',
+            'created_at',
+            [
+                'class' => ActionColumn::class,
+                'urlCreator' => function ($action, StoresTypeList $model, $key, $index, $column) {
+                    return Url::toRoute([$action, 'id' => $model->id]);
+                }
+            ],
+        ],
+    ]); ?>
+
+
+</div>
diff --git a/erp24/views/stores-type-list/update.php b/erp24/views/stores-type-list/update.php
new file mode 100644 (file)
index 0000000..875c11a
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\StoresTypeList $model */
+
+$this->title = 'Редактирование типа магазина: ' . $model->type_name;
+$this->params['breadcrumbs'][] = ['label' => 'Stores Type Lists', 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
+$this->params['breadcrumbs'][] = 'Update';
+?>
+<div class="stores-type-list-update p-4">
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary m-5']) ?>
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/stores-type-list/view.php b/erp24/views/stores-type-list/view.php
new file mode 100644 (file)
index 0000000..34503f3
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\StoresTypeList $model */
+
+$this->title = 'Тип магазина: ' . $model->type_name;
+$this->params['breadcrumbs'][] = ['label' => 'Stores Type Lists', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="stores-type-list-view p-4">
+    <?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary m-5']) ?>
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы хотите удалить?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'type_name',
+            'type_alias',
+            'type_description',
+            'created_at',
+        ],
+    ]) ?>
+
+</div>