1

我想构建一个自定义菜单输出,所以我调用这个类:

$pages = \Ip\Menu\Helper::getMenuItems('menu1');

它返回这个:

Array
(
[0] => Ip\Menu\Item Object
    (
        [title:protected] => Home
        [pageTitle:protected] => 
        [url:protected] => http://porto.gigaweb.me/home
        [target:protected] => 
        [selected:protected] => 
        [current:protected] => 1
        [children:protected] => Array
            (
                [0] => Ip\Menu\Item Object
                    (
                        [title:protected] => Lorem ipsum
                        [pageTitle:protected] => 
                        [url:protected] => http://porto.gigaweb.me/lorem-ipsumy
                        [target:protected] => 
                        [selected:protected] => 
                        [current:protected] => 
                        [children:protected] => 
                        [depth:protected] => 2
                        [disabled:protected] => 0
                        [blank:protected] => 0
                    )

                [1] => Ip\Menu\Item Object
                    (
                        [title:protected] => about
                        [pageTitle:protected] => 
                        [url:protected] => http://porto.gigaweb.me/about
                        [target:protected] => 
                        [selected:protected] => 
                        [current:protected] => 
                        [children:protected] => 
                        [depth:protected] => 2
                        [disabled:protected] => 0
                        [blank:protected] => 0
                    )
            )
        [depth:protected] => 1
        [disabled:protected] => 0
        [blank:protected] => 0
    )
)

我试图把它变成一个数组,但它返回像这样的值 [*title]。我想遍历它并输出值,但似乎做不到。

4

1 回答 1

0

它是一个对象数组。不是数组数组。所以你必须做这样的事情:

foreach ($pages as $menuItem) {
  $page->getTitle();
}

您可以在这里找到 $page 对象的其他方法http://www.impresspages.org/menu-item

请记住,您获取的是 MenuItem 对象,而不是 Page 对象。

于 2014-04-18T07:59:11.573 回答