/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product_cat::find(); $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(['cat_id' => $this->cat_id]); $query->andFilterWhere(['like', 'cat_name', $this->cat_name]); return $dataProvider; }
/** * Finds the Product_cat model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product_cat the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product_cat::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $model backend\models\Product */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="product-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'prod_name')->textInput(); ?> <?php echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(Product_cat::find()->all(), 'cat_id', 'cat_name'), ['prompt' => 'Select Category']); ?> <?php echo $form->field($model, 'file')->fileInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();
/** * @return \yii\db\ActiveQuery */ public function getCat() { return $this->hasOne(Product_cat::className(), ['cat_id' => 'cat_id']); }