0

私はそのような再帰モデル関数を持っています:

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空を返します。

なぜこれが起こるのかについてのアイデアはありますか?

4

2 に答える 2