/** * 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; }
/** * @return \yii\db\ActiveQuery */ public function getTopics() { return $this->hasMany(Topic::className(), ['SectionId' => 'SectionId']); }
/** * 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(); }
/** * @return \yii\db\ActiveQuery */ public function getTopics() { return $this->hasMany(Topic::className(), ['ParentId' => 'TopicId'])->orderBy('Order'); }
/** * @return \yii\db\ActiveQuery */ public function getTopic() { return $this->hasOne(Topic::className(), ['TopicId' => 'TopicId']); }