/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Parents::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(['parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'parent', $this->parent]); return $dataProvider; }
use lukisongroup\front\models\Parents; use lukisongroup\front\models\Child; $data = ["red" => "red", "green" => "green", "blue" => "blue", "orange" => "orange", "white" => "white", "black" => "black", "purple" => "purple", "cyan" => "cyan", "teal" => "teal"]; /* @var $this yii\web\View */ /* @var $model lukisongroup\child\models\Child */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="child-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'PARENT_ID')->widget(Select2::classname(), ['data' => ArrayHelper::map(Parents::find()->all(), 'parent_id', 'parent'), 'language' => 'en']); ?> <?php echo $form->field($model, 'CHILD_NAME')->textInput(['maxlength' => true]); ?> <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(); ?>
use kartik\select2\select2; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model lukisongroup\grandchild\models\Grandchild */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="grandchild-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'CHILD_ID')->dropDownList(ArrayHelper::map(Parents::find()->asArray()->all(), 'parent_id', 'parent'), ['id' => 'cat-id']); echo $form->field($model, 'PARENT_ID')->widget(\kartik\depdrop\DepDrop::classname(), ['options' => ['id' => 'subcat-id'], 'pluginOptions' => ['depends' => ['cat-id'], 'placeholder' => 'Select...', 'url' => Url::to(['get-child'])]]); ?> <?php echo $form->field($model, 'GRANDCHILD')->textInput(['maxlength' => true]); ?> <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();
public function getParents() { return $this->hasOne(Parents::className(), ['parent_id' => 'PARENT_ID']); }
/** * Finds the Parents model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Parents the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Parents::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }