codeigniter 行为不当:主控制器中的函数按预期工作但在助手 return 空数组中

codeigniter misbehave: function in main controller works as expected but in helper return empty array

我有以下函数,它从 table 中检索父类别,然后将其保存到一个数组中,直到找不到任何人为止。 当直接从 url 浏览器在主控制器中调用此函数时,此函数工作正常,但是当从 codeigniter 助手调用它并提供给 count() 函数时 return 空数组,其中没有元素。

// in codeigniter helper:
function get_category_ancestors($catId)
{
    $ci =& get_instance();
    static $categoryAncestors = array();
    $category = $ci->a_model->get_cat_parent($catId);
    if($category->num_rows() > 0)
    {
        $categoryParent = $category->row_array();
        $categoryAncestors[][$categoryParent["id"]] = $categoryParent["categoryName"];
        get_category_ancestors($categoryParent["id"]);
    }
    else
    {
        $inOrder = array_reverse($categoryAncestors);
        return $inOrder;
    }
}
// model: (for clear demonstration)
// two table: category and category_relation
public function get_cat_parent($categoryId)
{
    $this->db->select('category.*' );
    $this->db->from('category_relation');
    $this->db->where('category_relation.subCategoryId', $categoryId);
    $this->db->join('category', 'category.id=category_relation.categoryId');
    $query = $this->db->get();
    return $query;
}
// some other helper:(get_category_ancestors() caller)
$categoriesInOrder = get_category_ancestors($categoryId);   
$totallAncestors = count($categoriesInOrder); // =>error: Parameter must be an array or an object that implements Countable

必须 return get_category_ancestors 才能工作。 return get_category_ancestors($categoryParent["id"]); 不只是 get_category_ancestors($categoryParent["id"]);.