/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PriceCategoryModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { $query->where('1=0'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'formula', $this->formula]); return $dataProvider; }
/** * Finds the PriceCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PriceCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PriceCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <div class="price-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $model->isNewRecord ? $form->field($model, 'product_name')->textInput()->label('Product Name') : $form->field($model, 'product_name')->textInput(['ReadOnly' => true])->label('Product Name'); ?> <?php echo $form->field($model, 'product_id')->hiddenInput()->label(false); ?> <?php echo $form->field($model, 'price_category_id')->dropDownList(\backend\models\sales\PriceCategory::selectOptions(), ['style' => 'width:40%;']); ?> <?php echo $model->isNewRecord ? $form->field($model, 'price')->textInput(['style' => 'width:60%;']) : $form->field($model, 'price')->textInput(['ReadOnly' => true, 'style' => 'width:60%;']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * @return \yii\db\ActiveQuery */ public function getPriceCategory() { return $this->hasOne(PriceCategory::className(), ['id' => 'price_category_id']); }