Welcome Guest, Not a member yet? Register   Sign In
[UPDATED] Breadcrumbs from hierachical pages
#11

[eluser]Marcelo Kanzaki[/eluser]
hahaha ok. Here is the thing:

I've spent a little time debugging it and when i put return $crumbs at the end of the function it returns an array only with the first item. But the var_dump still does its job...

Code:
function bread_crumb ($page_id, $crumbs = array())
    {
        $page = $this->find_by_id($page_id);
        
        $crumbs[] = anchor('pages/'.$page->page_id, $page->page_title);
        
        $parent_id = $page->page_parent_id;
        
        echo '<pre>';
        
        var_dump($crumbs);
        
        var_dump($page->page_id);
        var_dump($parent_id);
        
        var_dump($page->page_title);
        
        echo '</pre>';
        
        if ($parent_id > 0)
        {
            $this->bread_crumb($page->page_parent_id, $crumbs);
        }
        
        return $crumbs;
    }

result

Code:
array(1) {
  [0]=>
  string(80) "buhu"
}
string(1) "5"
string(1) "3"
string(4) "buhu"

array(2) {
  [0]=>
  string(80) "buhu"
  [1]=>
  string(84) "Castelos"
}
string(1) "3"
string(1) "1"
string(8) "Castelos"

array(3) {
  [0]=>
  string(80) "buhu"
  [1]=>
  string(84) "Castelos"
  [2]=>
  string(83) "Turismo"
}
string(1) "1"
string(1) "0"
string(7) "Turismo"

array(1) { [0]=> string(80) "buhu" }


BUT when i put return $crumbs conditionaly

Code:
if ($parent_id > 0)
        {
            $this->bread_crumb($page->page_parent_id, $crumbs);
        }
        else
        {
            return $crumbs;
        }

then it returns NULL at the end:

Code:
array(1) {
  [0]=>
  string(80) "buhu"
}
string(1) "5"
string(1) "3"
string(4) "buhu"

array(2) {
  [0]=>
  string(80) "buhu"
  [1]=>
  string(84) "Castelos"
}
string(1) "3"
string(1) "1"
string(8) "Castelos"

array(3) {
  [0]=>
  string(80) "buhu"
  [1]=>
  string(84) "Castelos"
  [2]=>
  string(83) "Turismo"
}
string(1) "1"
string(1) "0"
string(7) "Turismo"

NULL

So basically the return is not working inside of the condition, wich is exacly what i need =)




Theme © iAndrew 2016 - Forum software by © MyBB