/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ProductSpecItem::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
<div class="modal-header"> <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span></button> <h4 id="myModalLabel2" class="modal-title">Add Product Specification</h4> </div> <div class="modal-body"> <div class="countries-form"> <?php $form = ActiveForm::begin(['id' => 'product_spec-form-update', 'enableAjaxValidation' => false, 'enableClientValidation' => true]); ?> <label>Item Name</label> <?php echo Select2::widget(['model' => $model_q, 'attribute' => 'item_name', 'data' => ArrayHelper::map(ProductSpecItem::find()->asArray()->all(), 'name', 'name'), 'options' => ['placeholder' => 'Select Item Name ...', 'multiple' => false], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model_q, 'item_val')->textInput(['maxlength' => 200]); ?> <input type="hidden" maxlength="200" name="ProductSpecification[cat_create]" class="form-control" value="ok"> <input type="hidden" maxlength="200" name="ProductSpecification[product_id]" class="form-control" value="<?php echo $model->id; ?> "> <div class="form-group"> <?php echo Html::submitButton('Add', ['class' => 'btn btn-primary']); ?>
public static function getFormAttribs() { return ['id' => ['type' => TabularForm::INPUT_HIDDEN, 'columnOptions' => ['hidden' => true]], 'item_name' => ['type' => TabularForm::INPUT_WIDGET, 'widgetClass' => \kartik\select2\Select2::classname(), 'options' => ['data' => ArrayHelper::map(ProductSpecItem::find()->asArray()->all(), 'name', 'name')]], 'item_val' => ['type' => TabularForm::INPUT_TEXT]]; }
/** * Finds the ProductSpecItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProductSpecItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProductSpecItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }