/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Products::find(); $query->joinWith(['manufacturer', 'manufacturer']); $dataProvider = new ActiveDataProvider(['query' => $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; } $query->andFilterWhere(['ID' => $this->ID, "{$this->tableName()}.Manufacturer" => $this->ManufacturerID, 'Measure' => $this->Measure, 'Price' => $this->Price, 'ProductType' => $this->ProductType]); $query->andFilterWhere(['like', 'Product', $this->Product])->andFilterWhere(['like', 'Article', $this->Article])->andFilterWhere(['like', 'Description', $this->Description])->andFilterWhere(['like', 'Manufacturers.Manufacturer', $this->Manufacturer]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Products::className(), ['Manufacturer' => 'ID']); }
use app\modules\warehouse\models\ProductsSearch; use yii\helpers\ArrayHelper; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model app\models\Contents */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="contents-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'Product')->dropDownList(ArrayHelper::map(Products::find()->orderBy('Manufacturer, Product')->all(), 'ID', 'productInfo', 'manufacturer.Manufacturer'), ['prompt' => Yii::t('app', 'Select...')]); ?> <!--Popup buttons--> <div class="form-group"> <?php echo Html::button(Yii::t('app', 'Search product'), ['class' => 'btn btn-primary btn-ajax-modal', 'value' => Url::to('/products/search'), 'data-target' => '#search-product-popup', 'data-toggle' => 'modal']); ?> <?php echo Html::button(Yii::t('app', 'Create product'), ['class' => 'btn btn-primary btn-ajax-modal', 'value' => Url::to('/products/create'), 'data-target' => '#create-product-popup', 'data-toggle' => 'modal']); ?> </div> <?php echo $form->field($model, 'Amount')->textInput();
/** * Relation to Products table */ public function getProduct() { return $this->hasOne(Products::className(), ['ID' => 'Product']); }
/** * Finds the Products model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Products the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Products::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }