Zend Navigation - setParent Zend_Navigation_Container

57 Views Asked by At

Currently working on some modifications inside a Zend Framework website. One of the things I've been trying to change is the navigation structure and caching of the website. Unfortunate I've came accros a small problem which I, for some reason, cant figure out.

The problem is that I've build up a multi dimensional tree structured array from a database, which I want to pass on to the Zend Navigation class. To me, the array seems legit but Zend throws back the setParent error 'Argument 1 passed to Zend_Navigation_Page::setParent() must be an instance of Zend_Navigation_Container, string given'.

After some debugging and research, I've found a test array (pastebin array) and pasted this in as the first argument array. The array looks (as far I can see) almost the same as my generated array (pastebin array).

I hope someone can help me move on with this problem.

Best regards.

2

There are 2 best solutions below

1
P. Sopacua On

You need to make sure that your array that you are sending to setParent is an instance of Zend_Navigation_Container.

First paste your array through Zend_Navigation() then paste the Instance through the setParent function of Zend_Navigation_Page.

0
Willem Poortman On

Found the problem. Thanks to the 'test array' I've added variables from my generated array one by one. After adding the $row['parent'] variable, the 'test array' also crashed into the setParent error.

foreach($elements as $key => $value) {

    $leaf = $value
    $value['swag'] = $value['parent'];

    unset($value['parent']);

}

Code above is not the exact code used, just the snippet which fixed this bug.