I have a recursive model function as such:
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;
}
Passing in a value of 40 for instance should return the following:
3_40
When I echo out the variable $path
within the model it does display the correct value, but when I call the function via my controller ie:
$result = $this->model_catalog_category->buildPaths(40);
$result
returns empty.
Any ideas on why this would be happening?
Thanks to andrewsi for this answer:
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'];
return $this->buildPaths($query->row['parent_id'], $output);
else:
$output = array_reverse ($output);
$path = implode ('_', $output);
return (string)$path;
endif;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다