/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = FaqType::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(['faq_type_id' => $this->faq_type_id]); $query->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
use yii\bootstrap\ActiveForm; //use yii\widgets\ActiveForm; use backend\models\FaqType; /* @var $this yii\web\View */ /* @var $model backend\models\Faq */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="faq-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'faq_type_id')->dropDownList(ArrayHelper::map(FaqType::find()->all(), 'faq_type_id', 'type'), ['prompt' => 'Select Type']); ?> <?php echo $form->field($model, 'question')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'answer')->textarea(['rows' => 6]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> <?php
/** * Finds the FaqType model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return FaqType the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = FaqType::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }