/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tutorialcategory::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(['id' => $this->id]); $query->andFilterWhere(['like', 'category', $this->category]); return $dataProvider; }
/** * Finds the Tutorialcategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tutorialcategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tutorialcategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="tutorial-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'title')->textInput(); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'id_category')->dropDownList(ArrayHelper::map(Tutorialcategory::find()->all(), 'id', 'category')); ?> </div> </div> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'description')->textArea(['rows' => '6']); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'image')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*']]); ?> </div>