Reputation: 1912
I have following problem and i tested it with data from the original documentation of the zend framework 2. I dont know if i miss something or if it is just a missing functionality.
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 the zend-navigation
module?
Thanks
Script
$container = new \Zend\Navigation\Navigation(
array(
array(
'label' => 'ACL page 1 (guest)',
'uri' => '#acl-guest',
'resource' => 'nav-guest',
'order' => 777,
'pages' => array(
array(
'label' => 'ACL page 1.1 (foo)',
'uri' => '#acl-foo',
'resource' => 'nav-foo',
'order' => 666
),
array(
'label' => 'ACL page 1.2 (bar)',
'uri' => '#acl-bar',
'resource' => 'nav-bar',
),
array(
'label' => 'ACL page 1.3 (baz)',
'uri' => '#acl-baz',
'resource' => 'nav-baz',
),
array(
'label' => 'ACL page 1.4 (bat)',
'uri' => '#acl-bat',
'resource' => 'nav-bat',
'order' => 111
),
),
),
array(
'label' => 'ACL page 2 (member)',
'uri' => '#acl-member',
'resource' => 'nav-member',
'order' => 555
)
)
);
foreach ($container as $page) {
echo $page->label."<br>";
if ($page->hasPages()) {
foreach ($page->getPages() as $page2) {
echo $page2->label."<br>";
}
}
}
die("ASD");
Output
ACL page 2 (member)
ACL page 1 (guest)
ACL page 1.1 (foo)
ACL page 1.2 (bar)
ACL page 1.3 (baz)
ACL page 1.4 (bat)
ASD
Upvotes: 0
Views: 278
Reputation: 81
Method $page->getPages()
return Array (docs). Elements are ordered only if list is Navigation object.
Try:
foreach ($container as $page) {
echo $page->label."<br>";
if ($page->hasPages()) {
$subpages = new \Zend\Navigation\Navigation($page->getPages());
foreach ($subpages as $page2) {
echo $page2->label."<br>";
}
}
}
Upvotes: 2