public function getCategoriesForParentRec($models, $id) { $categoryRow = $this->db()->select('*')->from('link_cats')->where(array('id' => $id))->execute()->fetchAssoc(); if (empty($categoryRow)) { return null; } if (!empty($categoryRow['parent_id'])) { $models = $this->getCategoriesForParentRec($models, $categoryRow['parent_id']); } $categoryModel = new CategoryModel(); $categoryModel->setId($categoryRow['id']); $categoryModel->setParentId($categoryRow['parent_id']); $categoryModel->setName($categoryRow['name']); $categoryModel->setDesc($categoryRow['desc']); $models[] = $categoryModel; return $models; }