Commit 6cc97b3074835d0671871aa2eb675c93a23d4fc7

Authored by Mihail
1 parent 8c0b2e3d

add details description crud

backend/controllers/DetailsDescriptionController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace backend\controllers;
  4 +
  5 +use Yii;
  6 +use common\models\DetailsDescription;
  7 +use common\models\DetailsDescriptionSearch;
  8 +use backend\components\base\BaseController;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * DetailsDescriptionController implements the CRUD actions for DetailsDescription model.
  14 + */
  15 +class DetailsDescriptionController extends BaseController
  16 +{
  17 + public $layout = "/column";
  18 +
  19 + public function behaviors()
  20 + {
  21 + return [
  22 + 'verbs' => [
  23 + 'class' => VerbFilter::className(),
  24 + 'actions' => [
  25 + 'delete' => ['post'],
  26 + ],
  27 + ],
  28 + ];
  29 + }
  30 +
  31 + /**
  32 + * Lists all DetailsDescription models.
  33 + * @return mixed
  34 + */
  35 + public function actionIndex()
  36 + {
  37 + $searchModel = new DetailsDescriptionSearch();
  38 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  39 +
  40 + return $this->render('index', [
  41 + 'searchModel' => $searchModel,
  42 + 'dataProvider' => $dataProvider,
  43 + ]);
  44 + }
  45 +
  46 +
  47 +
  48 + /**
  49 + * Updates an existing DetailsDescription model.
  50 + * If update is successful, the browser will be redirected to the 'view' page.
  51 + * @param string $name
  52 + * @param string $brand
  53 + * @return mixed
  54 + */
  55 + public function actionUpdate($name, $brand)
  56 + {
  57 + $model = $this->findModel($name, $brand);
  58 +
  59 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  60 + return $this->redirect(['view', 'name' => $model->name, 'brand' => $model->brand]);
  61 + } else {
  62 + return $this->render('update', [
  63 + 'model' => $model,
  64 + ]);
  65 + }
  66 + }
  67 +
  68 +
  69 +
  70 + /**
  71 + * Finds the DetailsDescription model based on its primary key value.
  72 + * If the model is not found, a 404 HTTP exception will be thrown.
  73 + * @param string $name
  74 + * @param string $brand
  75 + * @return DetailsDescription the loaded model
  76 + * @throws NotFoundHttpException if the model cannot be found
  77 + */
  78 + protected function findModel($name, $brand)
  79 + {
  80 + if (($model = DetailsDescription::findOne(['name' => $name, 'brand' => $brand])) !== null) {
  81 + return $model;
  82 + } else {
  83 + throw new NotFoundHttpException('The requested page does not exist.');
  84 + }
  85 + }
  86 +}
... ...
backend/views/details-description/_form.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\DetailsDescription */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="details-description-form">
  12 +
  13 + <?php $form = ActiveForm::begin(); ?>
  14 +
  15 + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
  16 +
  17 + <?= $form->field($model, 'brand')->textInput(['maxlength' => true]) ?>
  18 +
  19 + <?= $form->field($model, 'tecdoc_id')->textInput(['maxlength' => true]) ?>
  20 +
  21 + <?= $form->field($model, 'tecdoc_article')->textInput(['maxlength' => true]) ?>
  22 +
  23 + <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
  24 +
  25 + <?= $form->field($model, 'tecdoc_description')->textInput(['maxlength' => true]) ?>
  26 +
  27 + <?= $form->field($model, 'supplier_description')->textInput(['maxlength' => true]) ?>
  28 +
  29 + <?= $form->field($model, 'article')->textInput(['maxlength' => true]) ?>
  30 +
  31 + <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?>
  32 +
  33 + <?= $form->field($model, 'tecdoc_image')->textInput(['maxlength' => true]) ?>
  34 +
  35 + <?= $form->field($model, 'category_id')->textInput(['maxlength' => true]) ?>
  36 +
  37 + <?= $form->field($model, 'timestamp')->textInput() ?>
  38 +
  39 + <div class="form-group">
  40 + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  41 + </div>
  42 +
  43 + <?php ActiveForm::end(); ?>
  44 +
  45 +</div>
... ...
backend/views/details-description/_search.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\DetailsDescriptionSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="details-description-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'id') ?>
  19 +
  20 + <?= $form->field($model, 'name') ?>
  21 +
  22 + <?= $form->field($model, 'brand') ?>
  23 +
  24 + <?= $form->field($model, 'tecdoc_id') ?>
  25 +
  26 + <?= $form->field($model, 'tecdoc_article') ?>
  27 +
  28 + <?php // echo $form->field($model, 'description') ?>
  29 +
  30 + <?php // echo $form->field($model, 'tecdoc_description') ?>
  31 +
  32 + <?php // echo $form->field($model, 'supplier_description') ?>
  33 +
  34 + <?php // echo $form->field($model, 'article') ?>
  35 +
  36 + <?php // echo $form->field($model, 'image') ?>
  37 +
  38 + <?php // echo $form->field($model, 'tecdoc_image') ?>
  39 +
  40 + <?php // echo $form->field($model, 'category_id') ?>
  41 +
  42 + <?php // echo $form->field($model, 'timestamp') ?>
  43 +
  44 + <div class="form-group">
  45 + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
  46 + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
  47 + </div>
  48 +
  49 + <?php ActiveForm::end(); ?>
  50 +
  51 +</div>
... ...
backend/views/details-description/index.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel common\models\DetailsDescriptionSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = Yii::t('app', 'Details Descriptions');
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="details-description-index">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  17 +
  18 + <p>
  19 + <?= Html::a(Yii::t('app', 'Create Details Description'), ['create'], ['class' => 'btn btn-success']) ?>
  20 + </p>
  21 +
  22 + <?= GridView::widget([
  23 + 'dataProvider' => $dataProvider,
  24 + 'filterModel' => $searchModel,
  25 + 'columns' => [
  26 + ['class' => 'yii\grid\SerialColumn'],
  27 +
  28 + 'id',
  29 + 'name',
  30 + 'brand',
  31 + 'tecdoc_id',
  32 + 'tecdoc_article',
  33 + // 'description',
  34 + // 'tecdoc_description',
  35 + // 'supplier_description',
  36 + // 'article',
  37 + // 'image',
  38 + // 'tecdoc_image',
  39 + // 'category_id',
  40 + // 'timestamp',
  41 +
  42 + ['class' => 'yii\grid\ActionColumn'],
  43 + ],
  44 + ]); ?>
  45 +
  46 +</div>
... ...
backend/views/details-description/update.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model common\models\DetailsDescription */
  7 +
  8 +$this->title = Yii::t('app', 'Update {modelClass}: ', [
  9 + 'modelClass' => 'Details Description',
  10 +]) . ' ' . $model->name;
  11 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Details Descriptions'), 'url' => ['index']];
  12 +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name, 'brand' => $model->brand]];
  13 +$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
  14 +?>
  15 +<div class="details-description-update">
  16 +
  17 + <h1><?= Html::encode($this->title) ?></h1>
  18 +
  19 + <?= $this->render('_form', [
  20 + 'model' => $model,
  21 + ]) ?>
  22 +
  23 +</div>
... ...
backend/views/details-description/view.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model common\models\DetailsDescription */
  8 +
  9 +$this->title = $model->name;
  10 +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Details Descriptions'), 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="details-description-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a(Yii::t('app', 'Update'), ['update', 'name' => $model->name, 'brand' => $model->brand], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'name' => $model->name, 'brand' => $model->brand], [
  20 + 'class' => 'btn btn-danger',
  21 + 'data' => [
  22 + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
  23 + 'method' => 'post',
  24 + ],
  25 + ]) ?>
  26 + </p>
  27 +
  28 + <?= DetailView::widget([
  29 + 'model' => $model,
  30 + 'attributes' => [
  31 + 'id',
  32 + 'name',
  33 + 'brand',
  34 + 'tecdoc_id',
  35 + 'tecdoc_article',
  36 + 'description',
  37 + 'tecdoc_description',
  38 + 'supplier_description',
  39 + 'article',
  40 + 'image',
  41 + 'tecdoc_image',
  42 + 'category_id',
  43 + 'timestamp',
  44 + ],
  45 + ]) ?>
  46 +
  47 +</div>
... ...
common/models/DetailsDescriptionSearch.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use common\models\DetailsDescription;
  9 +
  10 +/**
  11 + * DetailsDescriptionSearch represents the model behind the search form about `common\models\DetailsDescription`.
  12 + */
  13 +class DetailsDescriptionSearch extends DetailsDescription
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['name', 'brand'], 'safe'],
  22 + ];
  23 + }
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function scenarios()
  29 + {
  30 + // bypass scenarios() implementation in the parent class
  31 + return Model::scenarios();
  32 + }
  33 +
  34 + /**
  35 + * Creates data provider instance with search query applied
  36 + *
  37 + * @param array $params
  38 + *
  39 + * @return ActiveDataProvider
  40 + */
  41 + public function search($params)
  42 + {
  43 + $query = DetailsDescription::find();
  44 +
  45 + $pagination = [
  46 + 'pageSize' => 20,
  47 + ];
  48 +
  49 + // удалим пустые параметры
  50 + if ( isset( $params['DetailsDescriptionSearch'] ) && is_array( $params['DetailsDescriptionSearch'] )) {
  51 + $params['DetailsDescriptionSearch'] = array_filter( $params['DetailsDescriptionSearch'], function($val){
  52 + return $val !="";
  53 + });
  54 + }
  55 +
  56 + $this->load($params);
  57 +
  58 + if (!$this->validate()) {
  59 +
  60 + $query->where('0=1');
  61 +
  62 + }
  63 +
  64 + if ( !$params || !$params['DetailsDescriptionSearch'] ) {
  65 + // если не переданы параметры - показываем первые 100 записей
  66 + $pagination = false;
  67 + $query->limit = 100;
  68 +
  69 + }
  70 +
  71 + $query->andFilterWhere([
  72 + 'name' => $this->name,
  73 + 'brand' => $this->brand,
  74 + ]);
  75 +
  76 + $dataProvider = new ActiveDataProvider([
  77 + 'query' => $query,
  78 + 'pagination' => $pagination,
  79 + ]);
  80 +
  81 + return $dataProvider;
  82 + }
  83 +}
... ...