/** * getSection is a public function * here we fetch all the topics under * the sectionId reference * @param INT $sectionId * @return ARRAY $result */ public function getSection($sectionId) { $query = Topic::find(); $query->where('ParentId IS NULL'); $query->andFilterWhere(['SectionId' => $sectionId]); $query->orderBy('order'); $query->with('topics'); $result = $query->all(); return $result; }
/** * To get a topic list of a specific section on ajax call. * */ public function actionAjaxtopictaglist() { $sectionId = Yii::$app->request->post("sectionId", ""); echo Html::tag('option', Html::encode("Please select"), ['value' => '']); if ($sectionId) { $query = Topic::find(); $query->andFilterWhere(['SectionId' => $sectionId]); $query->orderBy('Order'); $topics = $query->all(); if (!empty($topics)) { foreach ($topics as $topic) { echo Html::tag('option', Html::encode($topic->topicTexts[0]->Title), ['value' => $topic->TopicId]); } } } Yii::$app->end(); }