impresspages解析来自getMenuItems类的renturn数据

时间:2014-04-18 02:53:07

标签: arrays impresspages

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

$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]。 我想循环遍历它并输出值,但似乎无法做到。

1 个答案:

答案 0 :(得分:0)

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

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

您可以在http://www.impresspages.org/menu-item

找到$ page object的其他方法

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