我有一个递归模型函数:
public function buildPaths ($category_id, $current_path = array()) {
if (!empty ($current_path)):
$output = $current_path;
else:
$output = array(0 => $category_id);
endif;
$query = $this->db->query ("
SELECT parent_id
FROM {$this->prefix}category
WHERE category_id = '" . (int)$category_id . "'
AND status = '1'");
if ($query->row['parent_id'] != 0):
$output[] = $query->row['parent_id'];
$this->buildPaths($query->row['parent_id'], $output);
else:
$output = array_reverse ($output);
$path = implode ('_', $output);
return (string)$path;
endif;
}
例如,传入值 40 应返回以下内容:
3_40
当我$path
在模型中回显变量时,它确实显示了正确的值,但是当我通过控制器调用函数时,即:
$result = $this->model_catalog_category->buildPaths(40);
$result
返回空。
关于为什么会发生这种情况的任何想法?