From: fomichev Date: Wed, 15 Jan 2025 12:55:12 +0000 (+0300) Subject: Создание базового crud X-Git-Tag: 1.7~57^2~6 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=937b23503ba4f5df3c298c7a316070b85c747332;p=erp24_rep%2Fyii-erp24%2F.git Создание базового crud --- diff --git a/erp24/controllers/StoresTypeListController.php b/erp24/controllers/StoresTypeListController.php new file mode 100644 index 00000000..02e5b985 --- /dev/null +++ b/erp24/controllers/StoresTypeListController.php @@ -0,0 +1,144 @@ + [ + '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 index 00000000..4ad1b418 --- /dev/null +++ b/erp24/migrations/m250115_114940_create_stores_type_list_table.php @@ -0,0 +1,42 @@ +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 index 00000000..ceab1b50 --- /dev/null +++ b/erp24/records/StoresTypeList.php @@ -0,0 +1,51 @@ + 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 index 00000000..e22d2a26 --- /dev/null +++ b/erp24/views/stores-type-list/_form.php @@ -0,0 +1,28 @@ + + +
+ + + + field($model, 'type_name')->textInput(['maxlength' => true]) ?> + + field($model, 'type_alias')->textInput(['maxlength' => true]) ?> + + field($model, 'type_description')->textInput(['maxlength' => true]) ?> + + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/stores-type-list/create.php b/erp24/views/stores-type-list/create.php new file mode 100644 index 00000000..c5d59b29 --- /dev/null +++ b/erp24/views/stores-type-list/create.php @@ -0,0 +1,20 @@ +title = 'Создание типа магазина'; +$this->params['breadcrumbs'][] = ['label' => 'Stores Type Lists', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ 'btn btn-primary m-5']) ?> +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/stores-type-list/index.php b/erp24/views/stores-type-list/index.php new file mode 100644 index 00000000..fe65d02d --- /dev/null +++ b/erp24/views/stores-type-list/index.php @@ -0,0 +1,44 @@ +title = 'Тип магазина'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + + $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]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/stores-type-list/update.php b/erp24/views/stores-type-list/update.php new file mode 100644 index 00000000..875c11a3 --- /dev/null +++ b/erp24/views/stores-type-list/update.php @@ -0,0 +1,21 @@ +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'; +?> +
+ 'btn btn-primary m-5']) ?> +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/stores-type-list/view.php b/erp24/views/stores-type-list/view.php new file mode 100644 index 00000000..34503f3a --- /dev/null +++ b/erp24/views/stores-type-list/view.php @@ -0,0 +1,40 @@ +title = 'Тип магазина: ' . $model->type_name; +$this->params['breadcrumbs'][] = ['label' => 'Stores Type Lists', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ 'btn btn-primary m-5']) ?> +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы хотите удалить?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'type_name', + 'type_alias', + 'type_description', + 'created_at', + ], + ]) ?> + +