public function getCategories(&$data = [], $parent = NULL) { $category = Category::find()->where(['parent_id' => $parent, 'type' => 'post'])->all(); foreach ($category as $key => $value) { $data[$value->id] = $this->getIndent($value->indent) . $value->title; unset($category[$key]); $this->getCategories($data, $value->id); } return $data; }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }