Commit e1048e52493dbde4c48de508dec1ecf0205f4e0e
1 parent
4775a528
-Brand size started and Blog article fix
Showing
9 changed files
with
440 additions
and
0 deletions
Show diff stats
1 | +<?php | |
2 | + | |
3 | +namespace artweb\artbox\ecommerce\controllers; | |
4 | + | |
5 | +use Yii; | |
6 | +use artweb\artbox\ecommerce\models\BrandSize; | |
7 | +use artweb\artbox\ecommerce\models\BrandSizeSearch; | |
8 | +use yii\web\Controller; | |
9 | +use yii\web\NotFoundHttpException; | |
10 | +use yii\filters\VerbFilter; | |
11 | + | |
12 | +/** | |
13 | + * BrandSizeController implements the CRUD actions for BrandSize model. | |
14 | + */ | |
15 | +class BrandSizeController extends Controller | |
16 | +{ | |
17 | + /** | |
18 | + * @inheritdoc | |
19 | + */ | |
20 | + public function behaviors() | |
21 | + { | |
22 | + return [ | |
23 | + 'verbs' => [ | |
24 | + 'class' => VerbFilter::className(), | |
25 | + 'actions' => [ | |
26 | + 'delete' => ['POST'], | |
27 | + ], | |
28 | + ], | |
29 | + ]; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * Lists all BrandSize models. | |
34 | + * @return mixed | |
35 | + */ | |
36 | + public function actionIndex() | |
37 | + { | |
38 | + $searchModel = new BrandSizeSearch(); | |
39 | + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
40 | + | |
41 | + return $this->render('index', [ | |
42 | + 'searchModel' => $searchModel, | |
43 | + 'dataProvider' => $dataProvider, | |
44 | + ]); | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * Displays a single BrandSize model. | |
49 | + * @param integer $id | |
50 | + * @return mixed | |
51 | + */ | |
52 | + public function actionView($id) | |
53 | + { | |
54 | + return $this->render('view', [ | |
55 | + 'model' => $this->findModel($id), | |
56 | + ]); | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * Creates a new BrandSize model. | |
61 | + * If creation is successful, the browser will be redirected to the 'view' page. | |
62 | + * @return mixed | |
63 | + */ | |
64 | + public function actionCreate() | |
65 | + { | |
66 | + $model = new BrandSize(); | |
67 | + | |
68 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
69 | + return $this->redirect(['view', 'id' => $model->id]); | |
70 | + } else { | |
71 | + return $this->render('create', [ | |
72 | + 'model' => $model, | |
73 | + ]); | |
74 | + } | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * Updates an existing BrandSize model. | |
79 | + * If update is successful, the browser will be redirected to the 'view' page. | |
80 | + * @param integer $id | |
81 | + * @return mixed | |
82 | + */ | |
83 | + public function actionUpdate($id) | |
84 | + { | |
85 | + $model = $this->findModel($id); | |
86 | + | |
87 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
88 | + return $this->redirect(['view', 'id' => $model->id]); | |
89 | + } else { | |
90 | + return $this->render('update', [ | |
91 | + 'model' => $model, | |
92 | + ]); | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + /** | |
97 | + * Deletes an existing BrandSize model. | |
98 | + * If deletion is successful, the browser will be redirected to the 'index' page. | |
99 | + * @param integer $id | |
100 | + * @return mixed | |
101 | + */ | |
102 | + public function actionDelete($id) | |
103 | + { | |
104 | + $this->findModel($id)->delete(); | |
105 | + | |
106 | + return $this->redirect(['index']); | |
107 | + } | |
108 | + | |
109 | + /** | |
110 | + * Finds the BrandSize model based on its primary key value. | |
111 | + * If the model is not found, a 404 HTTP exception will be thrown. | |
112 | + * @param integer $id | |
113 | + * @return BrandSize the loaded model | |
114 | + * @throws NotFoundHttpException if the model cannot be found | |
115 | + */ | |
116 | + protected function findModel($id) | |
117 | + { | |
118 | + if (($model = BrandSize::findOne($id)) !== null) { | |
119 | + return $model; | |
120 | + } else { | |
121 | + throw new NotFoundHttpException('The requested page does not exist.'); | |
122 | + } | |
123 | + } | |
124 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artweb\artbox\ecommerce\models; | |
4 | + | |
5 | +use Yii; | |
6 | + | |
7 | +/** | |
8 | + * This is the model class for table "brand_size". | |
9 | + * | |
10 | + * @property integer $id | |
11 | + * @property integer $brand_id | |
12 | + * @property string $image | |
13 | + * | |
14 | + * @property Brand $brand | |
15 | + * @property BrandSizeToCategory[] $brandSizeToCategories | |
16 | + * @property Category[] $categories | |
17 | + */ | |
18 | +class BrandSize extends \yii\db\ActiveRecord | |
19 | +{ | |
20 | + /** | |
21 | + * @inheritdoc | |
22 | + */ | |
23 | + public static function tableName() | |
24 | + { | |
25 | + return 'brand_size'; | |
26 | + } | |
27 | + | |
28 | + /** | |
29 | + * @inheritdoc | |
30 | + */ | |
31 | + public function rules() | |
32 | + { | |
33 | + return [ | |
34 | + [['brand_id'], 'integer'], | |
35 | + [['image'], 'string', 'max' => 255], | |
36 | + [['brand_id'], 'exist', 'skipOnError' => true, 'targetClass' => Brand::className(), 'targetAttribute' => ['brand_id' => 'id']], | |
37 | + ]; | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * @inheritdoc | |
42 | + */ | |
43 | + public function attributeLabels() | |
44 | + { | |
45 | + return [ | |
46 | + 'id' => Yii::t('app', 'ID'), | |
47 | + 'brand_id' => Yii::t('app', 'Brand ID'), | |
48 | + 'image' => Yii::t('app', 'Image'), | |
49 | + ]; | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * @return \yii\db\ActiveQuery | |
54 | + */ | |
55 | + public function getBrand() | |
56 | + { | |
57 | + return $this->hasOne(Brand::className(), ['id' => 'brand_id']); | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * @return \yii\db\ActiveQuery | |
62 | + */ | |
63 | + public function getBrandSizeToCategories() | |
64 | + { | |
65 | + return $this->hasMany(BrandSizeToCategory::className(), ['brand_size_id' => 'id']); | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * @return \yii\db\ActiveQuery | |
70 | + */ | |
71 | + public function getCategories() | |
72 | + { | |
73 | + return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('brand_size_to_category', ['brand_size_id' => 'id']); | |
74 | + } | |
75 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace artweb\artbox\ecommerce\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | +use yii\data\ActiveDataProvider; | |
8 | +use artweb\artbox\ecommerce\models\BrandSize; | |
9 | + | |
10 | +/** | |
11 | + * BrandSizeSearch represents the model behind the search form about `artweb\artbox\ecommerce\models\BrandSize`. | |
12 | + */ | |
13 | +class BrandSizeSearch extends BrandSize | |
14 | +{ | |
15 | + /** | |
16 | + * @inheritdoc | |
17 | + */ | |
18 | + public function rules() | |
19 | + { | |
20 | + return [ | |
21 | + [['id', 'brand_id'], 'integer'], | |
22 | + [['image'], 'safe'], | |
23 | + ]; | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * @inheritdoc | |
28 | + */ | |
29 | + public function scenarios() | |
30 | + { | |
31 | + // bypass scenarios() implementation in the parent class | |
32 | + return Model::scenarios(); | |
33 | + } | |
34 | + | |
35 | + /** | |
36 | + * Creates data provider instance with search query applied | |
37 | + * | |
38 | + * @param array $params | |
39 | + * | |
40 | + * @return ActiveDataProvider | |
41 | + */ | |
42 | + public function search($params) | |
43 | + { | |
44 | + $query = BrandSize::find(); | |
45 | + | |
46 | + // add conditions that should always apply here | |
47 | + | |
48 | + $dataProvider = new ActiveDataProvider([ | |
49 | + 'query' => $query, | |
50 | + ]); | |
51 | + | |
52 | + $this->load($params); | |
53 | + | |
54 | + if (!$this->validate()) { | |
55 | + // uncomment the following line if you do not want to return any records when validation fails | |
56 | + // $query->where('0=1'); | |
57 | + return $dataProvider; | |
58 | + } | |
59 | + | |
60 | + // grid filtering conditions | |
61 | + $query->andFilterWhere([ | |
62 | + 'id' => $this->id, | |
63 | + 'brand_id' => $this->brand_id, | |
64 | + ]); | |
65 | + | |
66 | + $query->andFilterWhere(['like', 'image', $this->image]); | |
67 | + | |
68 | + return $dataProvider; | |
69 | + } | |
70 | +} | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artweb\artbox\ecommerce\models\BrandSize */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="brand-size-form"> | |
12 | + | |
13 | + <?php $form = ActiveForm::begin(); ?> | |
14 | + | |
15 | + <?= $form->field($model, 'brand_id')->textInput() ?> | |
16 | + | |
17 | + <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?> | |
18 | + | |
19 | + <div class="form-group"> | |
20 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
21 | + </div> | |
22 | + | |
23 | + <?php ActiveForm::end(); ?> | |
24 | + | |
25 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\ActiveForm; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artweb\artbox\ecommerce\models\BrandSizeSearch */ | |
8 | +/* @var $form yii\widgets\ActiveForm */ | |
9 | +?> | |
10 | + | |
11 | +<div class="brand-size-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, 'brand_id') ?> | |
21 | + | |
22 | + <?= $form->field($model, 'image') ?> | |
23 | + | |
24 | + <div class="form-group"> | |
25 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
26 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
27 | + </div> | |
28 | + | |
29 | + <?php ActiveForm::end(); ?> | |
30 | + | |
31 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artweb\artbox\ecommerce\models\BrandSize */ | |
8 | + | |
9 | +$this->title = Yii::t('app', 'Create Brand Size'); | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="brand-size-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 artweb\artbox\ecommerce\models\BrandSizeSearch */ | |
8 | +/* @var $dataProvider yii\data\ActiveDataProvider */ | |
9 | + | |
10 | +$this->title = Yii::t('app', 'Brand Sizes'); | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="brand-size-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 Brand Size'), ['create'], ['class' => 'btn btn-success']) ?> | |
20 | + </p> | |
21 | + <?= GridView::widget([ | |
22 | + 'dataProvider' => $dataProvider, | |
23 | + 'filterModel' => $searchModel, | |
24 | + 'columns' => [ | |
25 | + ['class' => 'yii\grid\SerialColumn'], | |
26 | + | |
27 | + 'id', | |
28 | + 'brand_id', | |
29 | + 'image', | |
30 | + | |
31 | + ['class' => 'yii\grid\ActionColumn'], | |
32 | + ], | |
33 | + ]); ?> | |
34 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | + | |
5 | +/* @var $this yii\web\View */ | |
6 | +/* @var $model artweb\artbox\ecommerce\models\BrandSize */ | |
7 | + | |
8 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
9 | + 'modelClass' => 'Brand Size', | |
10 | +]) . $model->id; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; | |
12 | +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; | |
13 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | |
14 | +?> | |
15 | +<div class="brand-size-update"> | |
16 | + | |
17 | + <h1><?= Html::encode($this->title) ?></h1> | |
18 | + | |
19 | + <?= $this->render('_form', [ | |
20 | + 'model' => $model, | |
21 | + ]) ?> | |
22 | + | |
23 | +</div> | ... | ... |
1 | +<?php | |
2 | + | |
3 | +use yii\helpers\Html; | |
4 | +use yii\widgets\DetailView; | |
5 | + | |
6 | +/* @var $this yii\web\View */ | |
7 | +/* @var $model artweb\artbox\ecommerce\models\BrandSize */ | |
8 | + | |
9 | +$this->title = $model->id; | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brand Sizes'), 'url' => ['index']]; | |
11 | +$this->params['breadcrumbs'][] = $this->title; | |
12 | +?> | |
13 | +<div class="brand-size-view"> | |
14 | + | |
15 | + <h1><?= Html::encode($this->title) ?></h1> | |
16 | + | |
17 | + <p> | |
18 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
19 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | |
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 | + 'brand_id', | |
33 | + 'image', | |
34 | + ], | |
35 | + ]) ?> | |
36 | + | |
37 | +</div> | ... | ... |