/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Producttypes::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['ProductTypeId' => $this->ProductTypeId, 'ProductCategoryId' => $this->ProductCategoryId, 'created_by' => $this->created_by, 'LastUpdatedBy' => $this->LastUpdatedBy, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at]); $query->andFilterWhere(['like', 'Name', $this->Name])->andFilterWhere(['like', 'Comment', $this->Comment]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; use common\models\Suppliers; use common\models\Brands; use common\models\Producttypes; use common\models\Productcategories; /* @var $this yii\web\View */ /* @var $model common\models\Products */ /* @var $form yii\bootstrap\ActiveForm */ $dataProductCategory = ArrayHelper::map(Productcategories::find()->asArray()->all(), 'ProductCategoryId', 'Name'); $dataSuppliers = ArrayHelper::map(Suppliers::find()->asArray()->all(), 'SupplierId', 'Name'); $dataBrands = ArrayHelper::map(Brands::find()->asArray()->all(), 'BrandId', 'Name'); $dataProducttypes = ArrayHelper::map(Producttypes::find()->asArray()->all(), 'ProducttypeId', 'Name'); ?> <div class="products-form"> <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?> <?php echo $form->field($model, 'Name', ['horizontalCssClasses' => ['wrapper' => 'col-sm-4']])->textInput(['maxlength' => 500]); ?> <?php echo $form->field($model, 'ProductCategoryId', ['horizontalCssClasses' => ['wrapper' => 'col-sm-3']])->dropDownList($dataProductCategory, ['prompt' => '----------Choose a Category----------']); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getProductType() { return $this->hasOne(Producttypes::className(), ['ProductTypeId' => 'ProductTypeId']); }
/** * Finds the Producttypes model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Producttypes the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Producttypes::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }