diff --git a/controllers/BrandSizeController.php b/controllers/BrandSizeController.php new file mode 100644 index 0000000..f4596f1 --- /dev/null +++ b/controllers/BrandSizeController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all BrandSize models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new BrandSizeSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single BrandSize model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new BrandSize model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new BrandSize(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing BrandSize model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing BrandSize model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the BrandSize model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return BrandSize the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = BrandSize::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/models/BrandSize.php b/models/BrandSize.php new file mode 100644 index 0000000..bf70bf6 --- /dev/null +++ b/models/BrandSize.php @@ -0,0 +1,75 @@ + 255], + [['brand_id'], 'exist', 'skipOnError' => true, 'targetClass' => Brand::className(), 'targetAttribute' => ['brand_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'brand_id' => Yii::t('app', 'Brand ID'), + 'image' => Yii::t('app', 'Image'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBrand() + { + return $this->hasOne(Brand::className(), ['id' => 'brand_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBrandSizeToCategories() + { + return $this->hasMany(BrandSizeToCategory::className(), ['brand_size_id' => 'id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCategories() + { + return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('brand_size_to_category', ['brand_size_id' => 'id']); + } +} diff --git a/models/BrandSizeSearch.php b/models/BrandSizeSearch.php new file mode 100644 index 0000000..80ec8b0 --- /dev/null +++ b/models/BrandSizeSearch.php @@ -0,0 +1,70 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'brand_id' => $this->brand_id, + ]); + + $query->andFilterWhere(['like', 'image', $this->image]); + + return $dataProvider; + } +} diff --git a/views/brand-size/_form.php b/views/brand-size/_form.php new file mode 100644 index 0000000..027b8d8 --- /dev/null +++ b/views/brand-size/_form.php @@ -0,0 +1,25 @@ + + +
+ = Html::a(Yii::t('app', 'Create Brand Size'), ['create'], ['class' => 'btn btn-success']) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'brand_id', + 'image', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'brand_id', + 'image', + ], + ]) ?> + +