From 6cc97b3074835d0671871aa2eb675c93a23d4fc7 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 13 Nov 2015 11:09:12 +0200 Subject: [PATCH] add details description crud --- backend/controllers/DetailsDescriptionController.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/details-description/_form.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ backend/views/details-description/_search.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/details-description/index.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ backend/views/details-description/update.php | 23 +++++++++++++++++++++++ backend/views/details-description/view.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ common/models/DetailsDescriptionSearch.php | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 381 insertions(+), 0 deletions(-) create mode 100644 backend/controllers/DetailsDescriptionController.php create mode 100644 backend/views/details-description/_form.php create mode 100644 backend/views/details-description/_search.php create mode 100644 backend/views/details-description/index.php create mode 100644 backend/views/details-description/update.php create mode 100644 backend/views/details-description/view.php create mode 100644 common/models/DetailsDescriptionSearch.php diff --git a/backend/controllers/DetailsDescriptionController.php b/backend/controllers/DetailsDescriptionController.php new file mode 100644 index 0000000..035ad15 --- /dev/null +++ b/backend/controllers/DetailsDescriptionController.php @@ -0,0 +1,86 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all DetailsDescription models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new DetailsDescriptionSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + + + /** + * Updates an existing DetailsDescription model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param string $name + * @param string $brand + * @return mixed + */ + public function actionUpdate($name, $brand) + { + $model = $this->findModel($name, $brand); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'name' => $model->name, 'brand' => $model->brand]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + + + /** + * Finds the DetailsDescription model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param string $name + * @param string $brand + * @return DetailsDescription the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($name, $brand) + { + if (($model = DetailsDescription::findOne(['name' => $name, 'brand' => $brand])) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/views/details-description/_form.php b/backend/views/details-description/_form.php new file mode 100644 index 0000000..d91dbe1 --- /dev/null +++ b/backend/views/details-description/_form.php @@ -0,0 +1,45 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'brand')->textInput(['maxlength' => true]) ?> + + field($model, 'tecdoc_id')->textInput(['maxlength' => true]) ?> + + field($model, 'tecdoc_article')->textInput(['maxlength' => true]) ?> + + field($model, 'description')->textInput(['maxlength' => true]) ?> + + field($model, 'tecdoc_description')->textInput(['maxlength' => true]) ?> + + field($model, 'supplier_description')->textInput(['maxlength' => true]) ?> + + field($model, 'article')->textInput(['maxlength' => true]) ?> + + field($model, 'image')->textInput(['maxlength' => true]) ?> + + field($model, 'tecdoc_image')->textInput(['maxlength' => true]) ?> + + field($model, 'category_id')->textInput(['maxlength' => true]) ?> + + field($model, 'timestamp')->textInput() ?> + +
+ isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/details-description/_search.php b/backend/views/details-description/_search.php new file mode 100644 index 0000000..21d7ac1 --- /dev/null +++ b/backend/views/details-description/_search.php @@ -0,0 +1,51 @@ + + + diff --git a/backend/views/details-description/index.php b/backend/views/details-description/index.php new file mode 100644 index 0000000..569d6b4 --- /dev/null +++ b/backend/views/details-description/index.php @@ -0,0 +1,46 @@ +title = Yii::t('app', 'Details Descriptions'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

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

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + 'brand', + 'tecdoc_id', + 'tecdoc_article', + // 'description', + // 'tecdoc_description', + // 'supplier_description', + // 'article', + // 'image', + // 'tecdoc_image', + // 'category_id', + // 'timestamp', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/backend/views/details-description/update.php b/backend/views/details-description/update.php new file mode 100644 index 0000000..495f26e --- /dev/null +++ b/backend/views/details-description/update.php @@ -0,0 +1,23 @@ +title = Yii::t('app', 'Update {modelClass}: ', [ + 'modelClass' => 'Details Description', +]) . ' ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Details Descriptions'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name, 'brand' => $model->brand]]; +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/details-description/view.php b/backend/views/details-description/view.php new file mode 100644 index 0000000..16cc2a2 --- /dev/null +++ b/backend/views/details-description/view.php @@ -0,0 +1,47 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Details Descriptions'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->name, 'brand' => $model->brand], ['class' => 'btn btn-primary']) ?> + $model->name, 'brand' => $model->brand], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + 'brand', + 'tecdoc_id', + 'tecdoc_article', + 'description', + 'tecdoc_description', + 'supplier_description', + 'article', + 'image', + 'tecdoc_image', + 'category_id', + 'timestamp', + ], + ]) ?> + +
diff --git a/common/models/DetailsDescriptionSearch.php b/common/models/DetailsDescriptionSearch.php new file mode 100644 index 0000000..ad0efba --- /dev/null +++ b/common/models/DetailsDescriptionSearch.php @@ -0,0 +1,83 @@ + 20, + ]; + + // удалим пустые параметры + if ( isset( $params['DetailsDescriptionSearch'] ) && is_array( $params['DetailsDescriptionSearch'] )) { + $params['DetailsDescriptionSearch'] = array_filter( $params['DetailsDescriptionSearch'], function($val){ + return $val !=""; + }); + } + + $this->load($params); + + if (!$this->validate()) { + + $query->where('0=1'); + + } + + if ( !$params || !$params['DetailsDescriptionSearch'] ) { + // если не переданы параметры - показываем первые 100 записей + $pagination = false; + $query->limit = 100; + + } + + $query->andFilterWhere([ + 'name' => $this->name, + 'brand' => $this->brand, + ]); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => $pagination, + ]); + + return $dataProvider; + } +} -- libgit2 0.21.4