/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tbtype::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $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', 'Name', $this->Name]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTypes() { return $this->hasOne(Tbtype::className(), ['ID' => 'type']); }
?> <?php echo $form->field($model, 'tag')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'content')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'file')->fileInput(); ?> <?php echo $form->field($model, 'type')->dropDownList(ArrayHelper::map(Tbtype::find()->all(), 'ID', 'Name'), ['prompt' => 'Select Category']); ?> <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(); ?> </div>
/** * Finds the Tbtype model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tbtype the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tbtype::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }