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; }
protected function categories(&$data = [], $parent = NULL) { $category = Category::find()->where(['parent_id' => $parent, 'type' => 'post'])->all(); foreach ($category as $key => $value) { $data[] = $value; unset($category[$key]); $this->categories($data, $value->id); } return $data; }