/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PatternType::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, 'is_editor' => $this->is_editor]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'alias', $this->alias]); return $dataProvider; }
/** * Finds the PatternType model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PatternType the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PatternType::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="domain-pattern-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'domain_id')->dropdownList(\backend\models\Domain::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Domain:'])->label('Domain Name'); ?> <?php echo $form->field($model, 'model_id')->dropdownList(\backend\models\PatternModel::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Pattern Model:'])->label('Pattern Model Name'); ?> <?php echo $form->field($model, 'type_id')->dropdownList(\backend\models\PatternType::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Pattern Type:'])->label('Pattern Type Name'); ?> <?php echo $form->field($model, 'value')->textarea(['rows' => 6]); ?> <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 getType() { return $this->hasOne(PatternType::className(), ['id' => 'type_id']); }