Commit dc7acae552f2ccd102d1d032a0f8155703f9af91
1 parent
86aa54e0
Importers CRUD
Showing
9 changed files
with
494 additions
and
1 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace backend\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use backend\models\Importers; | |
7 | +use backend\models\ImportersSearch; | |
8 | +use yii\web\Controller; | |
9 | +use yii\web\NotFoundHttpException; | |
10 | +use yii\filters\VerbFilter; | |
11 | + | |
12 | +/** | |
13 | + * ImportersController implements the CRUD actions for Importers model. | |
14 | + */ | |
15 | +class ImportersController extends Controller | |
16 | +{ | |
17 | + public function behaviors() | |
18 | + { | |
19 | + return [ | |
20 | + 'verbs' => [ | |
21 | + 'class' => VerbFilter::className(), | |
22 | + 'actions' => [ | |
23 | + 'delete' => ['post'], | |
24 | + ], | |
25 | + ], | |
26 | + ]; | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * Lists all Importers models. | |
31 | + * @return mixed | |
32 | + */ | |
33 | + public function actionIndex() | |
34 | + { | |
35 | + $searchModel = new ImportersSearch(); | |
36 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
37 | + | |
38 | + return $this->render('index', [ | |
39 | + 'searchModel' => $searchModel, | |
40 | + 'dataProvider' => $dataProvider, | |
41 | + ]); | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * Displays a single Importers model. | |
46 | + * @param integer $id | |
47 | + * @return mixed | |
48 | + */ | |
49 | + public function actionView($id) | |
50 | + { | |
51 | + return $this->render('view', [ | |
52 | + 'model' => $this->findModel($id), | |
53 | + ]); | |
54 | + } | |
55 | + | |
56 | + /** | |
57 | + * Creates a new Importers model. | |
58 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
59 | + * @return mixed | |
60 | + */ | |
61 | + public function actionCreate() | |
62 | + { | |
63 | + $model = new Importers(); | |
64 | + | |
65 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
66 | + return $this->redirect(['view', 'id' => $model->id]); | |
67 | + } else { | |
68 | + return $this->render('create', [ | |
69 | + 'model' => $model, | |
70 | + ]); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * Updates an existing Importers model. | |
76 | + * If update is successful, the browser will be redirected to the 'view' page. | |
77 | + * @param integer $id | |
78 | + * @return mixed | |
79 | + */ | |
80 | + public function actionUpdate($id) | |
81 | + { | |
82 | + $model = $this->findModel($id); | |
83 | + | |
84 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
85 | + return $this->redirect(['view', 'id' => $model->id]); | |
86 | + } else { | |
87 | + return $this->render('update', [ | |
88 | + 'model' => $model, | |
89 | + ]); | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * Deletes an existing Importers model. | |
95 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
96 | + * @param integer $id | |
97 | + * @return mixed | |
98 | + */ | |
99 | + public function actionDelete($id) | |
100 | + { | |
101 | + $this->findModel($id)->delete(); | |
102 | + | |
103 | + return $this->redirect(['index']); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * Finds the Importers model based on its primary key value. | |
108 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
109 | + * @param integer $id | |
110 | + * @return Importers the loaded model | |
111 | + * @throws NotFoundHttpException if the model cannot be found | |
112 | + */ | |
113 | + protected function findModel($id) | |
114 | + { | |
115 | + if (($model = Importers::findOne($id)) !== null) { | |
116 | + return $model; | |
117 | + } else { | |
118 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
119 | + } | |
120 | + } | |
121 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace backend\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use backend\models\Importers; | |
9 | + | |
10 | +/** | |
11 | + * ImportersSearch represents the model behind the search form about `backend\models\Importers`. | |
12 | + */ | |
13 | +class ImportersSearch extends Importers | |
14 | +{ | |
15 | + /** | |
16 | + * @inheritdoc | |
17 | + */ | |
18 | + public function rules() | |
19 | + { | |
20 | + return [ | |
21 | + [['id', 'currency_id', 'active', 'PARSER_IS_ACTIVE', 'PARSER_COLUMN_COUNT', 'PARSER_FIELD_BRAND', 'PARSER_FIELD_ARTICLE', 'PARSER_FIELD_ARTICLE_PREFIX', 'PARSER_FIELD_PRICE', 'PARSER_FIELD_DESCR', 'PARSER_FIELD_BOX', 'PARSER_FIELD_ADD_BOX', 'PARSER_FIELD_GROUP_RG'], 'integer'], | |
22 | + [['code', 'name', 'name_price', 'delivery', 'email', 'info', 'PARSER_FIELD_SIGN', 'price_date_update'], 'safe'], | |
23 | + [['PARSER_FIELD_MULTIPLIER'], 'number'], | |
24 | + ]; | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * @inheritdoc | |
29 | + */ | |
30 | + public function scenarios() | |
31 | + { | |
32 | + // bypass scenarios() implementation in the parent class | |
33 | + return Model::scenarios(); | |
34 | + } | |
35 | + | |
36 | + /** | |
37 | + * Creates data provider instance with search query applied | |
38 | + * | |
39 | + * @param array $params | |
40 | + * | |
41 | + * @return ActiveDataProvider | |
42 | + */ | |
43 | + public function search($params) | |
44 | + { | |
45 | + $query = Importers::find(); | |
46 | + | |
47 | + $dataProvider = new ActiveDataProvider([ | |
48 | + 'query' => $query, | |
49 | + ]); | |
50 | + | |
51 | + $this->load($params); | |
52 | + | |
53 | + if (!$this->validate()) { | |
54 | + // uncomment the following line if you do not want to return any records when validation fails | |
55 | + // $query->where('0=1'); | |
56 | + return $dataProvider; | |
57 | + } | |
58 | + | |
59 | + $query->andFilterWhere([ | |
60 | + 'id' => $this->id, | |
61 | + 'currency_id' => $this->currency_id, | |
62 | + 'active' => $this->active, | |
63 | + 'PARSER_IS_ACTIVE' => $this->PARSER_IS_ACTIVE, | |
64 | + 'PARSER_COLUMN_COUNT' => $this->PARSER_COLUMN_COUNT, | |
65 | + 'PARSER_FIELD_BRAND' => $this->PARSER_FIELD_BRAND, | |
66 | + 'PARSER_FIELD_ARTICLE' => $this->PARSER_FIELD_ARTICLE, | |
67 | + 'PARSER_FIELD_ARTICLE_PREFIX' => $this->PARSER_FIELD_ARTICLE_PREFIX, | |
68 | + 'PARSER_FIELD_PRICE' => $this->PARSER_FIELD_PRICE, | |
69 | + 'PARSER_FIELD_DESCR' => $this->PARSER_FIELD_DESCR, | |
70 | + 'PARSER_FIELD_BOX' => $this->PARSER_FIELD_BOX, | |
71 | + 'PARSER_FIELD_ADD_BOX' => $this->PARSER_FIELD_ADD_BOX, | |
72 | + 'PARSER_FIELD_GROUP_RG' => $this->PARSER_FIELD_GROUP_RG, | |
73 | + 'PARSER_FIELD_MULTIPLIER' => $this->PARSER_FIELD_MULTIPLIER, | |
74 | + 'price_date_update' => $this->price_date_update, | |
75 | + ]); | |
76 | + | |
77 | + $query->andFilterWhere(['like', 'code', $this->code]) | |
78 | + ->andFilterWhere(['like', 'name', $this->name]) | |
79 | + ->andFilterWhere(['like', 'name_price', $this->name_price]) | |
80 | + ->andFilterWhere(['like', 'delivery', $this->delivery]) | |
81 | + ->andFilterWhere(['like', 'email', $this->email]) | |
82 | + ->andFilterWhere(['like', 'info', $this->info]) | |
83 | + ->andFilterWhere(['like', 'PARSER_FIELD_SIGN', $this->PARSER_FIELD_SIGN]); | |
84 | + | |
85 | + return $dataProvider; | |
86 | + } | |
87 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model backend\models\Importers */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="importers-form"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin(); ?> | |
14 | + | |
15 | + <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?> | |
16 | + | |
17 | + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | |
18 | + | |
19 | + <?= $form->field($model, 'name_price')->textInput(['maxlength' => true]) ?> | |
20 | + | |
21 | + <?= $form->field($model, 'currency_id')->textInput() ?> | |
22 | + | |
23 | + <?= $form->field($model, 'delivery')->textInput(['maxlength' => true]) ?> | |
24 | + | |
25 | + <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?> | |
26 | + | |
27 | + <?= $form->field($model, 'info')->textarea(['rows' => 6]) ?> | |
28 | + | |
29 | + <?= $form->field($model, 'active')->textInput() ?> | |
30 | + | |
31 | + <?= $form->field($model, 'PARSER_IS_ACTIVE')->textInput() ?> | |
32 | + | |
33 | + <?= $form->field($model, 'PARSER_COLUMN_COUNT')->textInput() ?> | |
34 | + | |
35 | + <?= $form->field($model, 'PARSER_FIELD_BRAND')->textInput() ?> | |
36 | + | |
37 | + <?= $form->field($model, 'PARSER_FIELD_ARTICLE')->textInput() ?> | |
38 | + | |
39 | + <?= $form->field($model, 'PARSER_FIELD_ARTICLE_PREFIX')->textInput() ?> | |
40 | + | |
41 | + <?= $form->field($model, 'PARSER_FIELD_PRICE')->textInput() ?> | |
42 | + | |
43 | + <?= $form->field($model, 'PARSER_FIELD_DESCR')->textInput() ?> | |
44 | + | |
45 | + <?= $form->field($model, 'PARSER_FIELD_BOX')->textInput() ?> | |
46 | + | |
47 | + <?= $form->field($model, 'PARSER_FIELD_ADD_BOX')->textInput() ?> | |
48 | + | |
49 | + <?= $form->field($model, 'PARSER_FIELD_GROUP_RG')->textInput() ?> | |
50 | + | |
51 | + <?= $form->field($model, 'PARSER_FIELD_SIGN')->textInput(['maxlength' => true]) ?> | |
52 | + | |
53 | + <?= $form->field($model, 'PARSER_FIELD_MULTIPLIER')->textInput() ?> | |
54 | + | |
55 | + <?= $form->field($model, 'price_date_update')->textInput() ?> | |
56 | + | |
57 | + <div class="form-group"> | |
58 | + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
59 | + </div> | |
60 | + | |
61 | + <?php ActiveForm::end(); ?> | |
62 | + | |
63 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model backend\models\ImportersSearch */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="importers-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, 'code') ?> | |
21 | + | |
22 | + <?= $form->field($model, 'name') ?> | |
23 | + | |
24 | + <?= $form->field($model, 'name_price') ?> | |
25 | + | |
26 | + <?= $form->field($model, 'currency_id') ?> | |
27 | + | |
28 | + <?php // echo $form->field($model, 'delivery') ?> | |
29 | + | |
30 | + <?php // echo $form->field($model, 'email') ?> | |
31 | + | |
32 | + <?php // echo $form->field($model, 'info') ?> | |
33 | + | |
34 | + <?php // echo $form->field($model, 'active') ?> | |
35 | + | |
36 | + <?php // echo $form->field($model, 'PARSER_IS_ACTIVE') ?> | |
37 | + | |
38 | + <?php // echo $form->field($model, 'PARSER_COLUMN_COUNT') ?> | |
39 | + | |
40 | + <?php // echo $form->field($model, 'PARSER_FIELD_BRAND') ?> | |
41 | + | |
42 | + <?php // echo $form->field($model, 'PARSER_FIELD_ARTICLE') ?> | |
43 | + | |
44 | + <?php // echo $form->field($model, 'PARSER_FIELD_ARTICLE_PREFIX') ?> | |
45 | + | |
46 | + <?php // echo $form->field($model, 'PARSER_FIELD_PRICE') ?> | |
47 | + | |
48 | + <?php // echo $form->field($model, 'PARSER_FIELD_DESCR') ?> | |
49 | + | |
50 | + <?php // echo $form->field($model, 'PARSER_FIELD_BOX') ?> | |
51 | + | |
52 | + <?php // echo $form->field($model, 'PARSER_FIELD_ADD_BOX') ?> | |
53 | + | |
54 | + <?php // echo $form->field($model, 'PARSER_FIELD_GROUP_RG') ?> | |
55 | + | |
56 | + <?php // echo $form->field($model, 'PARSER_FIELD_SIGN') ?> | |
57 | + | |
58 | + <?php // echo $form->field($model, 'PARSER_FIELD_MULTIPLIER') ?> | |
59 | + | |
60 | + <?php // echo $form->field($model, 'price_date_update') ?> | |
61 | + | |
62 | + <div class="form-group"> | |
63 | + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | |
64 | + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | |
65 | + </div> | |
66 | + | |
67 | + <?php ActiveForm::end(); ?> | |
68 | + | |
69 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model backend\models\Importers */ | |
8 | + | |
9 | +$this->title = 'Create Importers'; | |
10 | +$this->params['breadcrumbs'][] = ['label' => 'Importers', 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="importers-create"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <?= $this->render('_form', [ | |
18 | + 'model' => $model, | |
19 | + ]) ?> | |
20 | + | |
21 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\grid\GridView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $searchModel backend\models\ImportersSearch */ | |
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
9 | + | |
10 | +$this->title = 'Importers'; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="importers-index"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
17 | + | |
18 | + <p> | |
19 | + <?= Html::a('Create Importers', ['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 | + 'code', | |
30 | + 'name', | |
31 | + 'name_price', | |
32 | + 'currency_id', | |
33 | + // 'delivery', | |
34 | + // 'email:email', | |
35 | + // 'info:ntext', | |
36 | + // 'active', | |
37 | + // 'PARSER_IS_ACTIVE', | |
38 | + // 'PARSER_COLUMN_COUNT', | |
39 | + // 'PARSER_FIELD_BRAND', | |
40 | + // 'PARSER_FIELD_ARTICLE', | |
41 | + // 'PARSER_FIELD_ARTICLE_PREFIX', | |
42 | + // 'PARSER_FIELD_PRICE', | |
43 | + // 'PARSER_FIELD_DESCR', | |
44 | + // 'PARSER_FIELD_BOX', | |
45 | + // 'PARSER_FIELD_ADD_BOX', | |
46 | + // 'PARSER_FIELD_GROUP_RG', | |
47 | + // 'PARSER_FIELD_SIGN', | |
48 | + // 'PARSER_FIELD_MULTIPLIER', | |
49 | + // 'price_date_update', | |
50 | + | |
51 | + ['class' => 'yii\grid\ActionColumn'], | |
52 | + ], | |
53 | + ]); ?> | |
54 | + | |
55 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model backend\models\Importers */ | |
7 | + | |
8 | +$this->title = 'Update Importers: ' . ' ' . $model->name; | |
9 | +$this->params['breadcrumbs'][] = ['label' => 'Importers', 'url' => ['index']]; | |
10 | +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; | |
11 | +$this->params['breadcrumbs'][] = 'Update'; | |
12 | +?> | |
13 | +<div class="importers-update"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <?= $this->render('_form', [ | |
18 | + 'model' => $model, | |
19 | + ]) ?> | |
20 | + | |
21 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model backend\models\Importers */ | |
8 | + | |
9 | +$this->title = $model->name; | |
10 | +$this->params['breadcrumbs'][] = ['label' => 'Importers', 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="importers-view"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <p> | |
18 | + <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
19 | + <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |
20 | + 'class' => 'btn btn-danger', | |
21 | + 'data' => [ | |
22 | + 'confirm' => '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 | + 'code', | |
33 | + 'name', | |
34 | + 'name_price', | |
35 | + 'currency_id', | |
36 | + 'delivery', | |
37 | + 'email:email', | |
38 | + 'info:ntext', | |
39 | + 'active', | |
40 | + 'PARSER_IS_ACTIVE', | |
41 | + 'PARSER_COLUMN_COUNT', | |
42 | + 'PARSER_FIELD_BRAND', | |
43 | + 'PARSER_FIELD_ARTICLE', | |
44 | + 'PARSER_FIELD_ARTICLE_PREFIX', | |
45 | + 'PARSER_FIELD_PRICE', | |
46 | + 'PARSER_FIELD_DESCR', | |
47 | + 'PARSER_FIELD_BOX', | |
48 | + 'PARSER_FIELD_ADD_BOX', | |
49 | + 'PARSER_FIELD_GROUP_RG', | |
50 | + 'PARSER_FIELD_SIGN', | |
51 | + 'PARSER_FIELD_MULTIPLIER', | |
52 | + 'price_date_update', | |
53 | + ], | |
54 | + ]) ?> | |
55 | + | |
56 | +</div> | ... | ... |
backend/views/layouts/column.php
... | ... | @@ -291,7 +291,7 @@ $this->beginContent('@app/views/layouts/main.php'); |
291 | 291 | ], |
292 | 292 | ['label' => 'Управление ролями', 'url' => ['#'], 'items' => [ |
293 | 293 | ['label' => 'Покупатели', 'url' => ['accounts/index']], |
294 | - ['label' => 'Поставщики', 'url' => '#'], | |
294 | + ['label' => 'Поставщики', 'url' => ['importers/index']], | |
295 | 295 | ['label' => 'Администраторы', 'url' => '#'], |
296 | 296 | ], |
297 | 297 | ], | ... | ... |