Closed FabianKoestring closed 9 years ago
@froschdesign - Are you the maintainer?
@FabianKoestring No, but I worked on the component since version 1.8.
I'll look into it.
@FabianKoestring Here is the problem:
foreach ($page->getPages() as $page2) {}
getPages()
is wrong. Use the page directly, because page is a RecursiveIterator
itself.
foreach ($page as $subPage) {}
Here is an unit test:
public function testIterationWithChildrenShouldBeOrderAware()
{
$nav = new Zend_Navigation(
[
[
'label' => 'Page 1',
'uri' => '#',
],
[
'label' => 'Page 2',
'uri' => '#',
'order' => -1,
'pages' => [
[
'label' => 'Page 2.1',
'uri' => '#',
'order' => 3,
],
[
'label' => 'Page 2.2',
'uri' => '#',
'order' => 2,
],
[
'label' => 'Page 2.3',
'uri' => '#',
'order' => 1,
],
],
],
[
'label' => 'Page 3',
'uri' => '#',
],
[
'label' => 'Page 4',
'uri' => '#',
'order' => 100,
],
[
'label' => 'Page 5',
'uri' => '#',
],
]
);
$expected = [
'Page 2',
'Page 2.3',
'Page 2.2',
'Page 2.1',
'Page 1',
'Page 3',
'Page 5',
'Page 4',
];
$actual = array();
foreach ($nav as $page) {
$actual[] = $page->getLabel();
if ($page->hasChildren()) {
foreach ($page as $subPage) {
$actual[] = $subPage->getLabel();
}
}
}
$this->assertEquals($expected, $actual);
}
Test result: Okay
@froschdesign
Oh no. Thank you very much. Works like a charm!
@FabianKoestring You are welcome.
In the following example i create a navigation with two levels and then print the navigation labels with echo. As you can see i set an order for both first level pages and for two second level pages. If you look at my output you can see that only the first level pages are in right order. The second level pages arent in right order.
For every level you put in a navigation greater than level one, the order isnt changed.
Anybody of you have the same problem or can tell me what iam doing wrong? Or is this a not given functionality of this module?
Testscript
Output