/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Section::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'level_id' => $this->level_id]); $query->andFilterWhere(['like', 'section_name', $this->section_name]); return $dataProvider; }
public function actionLists($id) { $countSection = Section::find()->where(['level_id' => $id])->count(); $Section = Section::find()->where(['level_id' => $id])->all(); if ($countSection > 0) { foreach ($Section as $section) { echo "<option value'" . $section->id . "'>" . $section->section_name . "</option>"; } } else { echo "<option></option>"; } }
/** * @return \yii\db\ActiveQuery */ public function getSections() { return $this->hasMany(Section::className(), ['level_id' => 'id']); }