/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductUnit::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Finds the ProductUnit model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProductUnit the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProductUnit::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<!--<div class="product-form">--> <div class="row"> <div class="col-lg-4 col-md-5"> <?php $form = ActiveForm::begin(); ?> <div class="col-lg-12"> <?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?> </div> <div class="col-lg-12"> <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> </div> <div class="col-lg-12"> <?php // echo $form->field($model, 'product_unit_id')->textInput() ?> <?php echo $form->field($model, 'product_unit_id', [])->dropDownList(ArrayHelper::map(ProductUnit::find()->all(), "id", "name"), ['class' => 'form-control', 'prompt' => Yii::t('app', 'Select')]); ?> </div> <div class="col-lg-12"> <?php echo $form->field($model, 'product_group_id')->textInput(['class' => 'form-control hidden'])->label(false) ?> <label class="control-label" for="txtProductGroupId"><?= Yii::t('app', 'Product Group') ?></label> <div class="input-group"> <a href="#" onclick="selectItem('product/list-group-modal', '<?php echo Yii::t('app', 'Select Group', "product-product_group_id", "txtProductGroupName") ?>')" class="btn btn-primary input-group-addon" data-toggle="modal" data-pjax="#modalbox .modal-body" data-target="#modalbox"> <i class="glyphicon glyphicon-search"></i> </a> <input type="text" id="txtProductGroupId" class="form-control" value="<?= @$model->productGroup->code ?>" /> <input type="text" id="txtProductGroupName" class="form-control input-group-addon readonly" value="<?= @$model->productGroup->name ?>" /> </div> <div class="help-block"></div>