bmcclure / CakePHP-Menu-Plugin

A CakePHP 2.0 plugin designed to help build menus in the controller and display them in the view
MIT License
17 stars 9 forks source link

Only last children from menu renders #10

Closed Fuhrmann closed 12 years ago

Fuhrmann commented 12 years ago

Ben, I have this Menu, loaded using a Model:

\app\Model\Menu.php (line 176)

array(
    (int) 77 => array(
        'title' => 'Musicas',
        'url' => array(
            'controller' => 'musicas',
            'action' => 'index'
        )
    ),
    (int) 78 => array(
        'title' => 'Desenvolvedor',
        'url' => 'javascript:void(0)',
        'children' => array(
            (int) 0 => array(
                'title' => 'Grupos de Usuários',
                'url' => array(
                    'controller' => 'grupos',
                    'action' => 'index'
                )
            ),
            (int) 1 => array(
                'title' => 'Grupos de Permissões',
                'url' => array(
                    'controller' => 'permissoes',
                    'action' => 'index'
                )
            ),
            (int) 2 => array(
                'title' => 'Usuários',
                'url' => array(
                    'controller' => 'usuarios',
                    'action' => 'index'
                )
            ),
            (int) 3 => array(
                'title' => 'Permissões',
                'url' => array(
                    'controller' => 'permissoes',
                    'action' => 'index'
                )
            ),
            (int) 4 => array(
                'title' => 'Menus',
                'url' => array(
                    'controller' => 'menus',
                    'action' => 'index'
                )
            )
        )
    )
)

The strange thing is when I tell the plugin to render my menu, only the last children is rendered:

(int) 4 => array(
                'title' => 'Menus',
                'url' => array(
                    'controller' => 'menus',
                    'action' => 'index'
                )
            )

Maybe I'm doing something wrong when populating the menu array, I don't know. But what I'm doing is just getting all the menu list from database and put them in an array.

Thanks.

bmcclure commented 12 years ago

Your array looks right, and that's how the plugin worked in the past. To be honest, I think I've only been working with simple menus since I rewrote the plugin a couple weeks ago, so it very well could be a bug that I just haven't noticed yet.

Sorry about that! I'm investigating now what the issue might be and should have an answer for you shortly.

Just to clarify, you're getting all parent items rendered, but only a single (the last) child when there are children?

Fuhrmann commented 12 years ago

"Just to clarify, you're getting all parent items rendered, but only a single (the last) child when there are children?"

Yes, exactly! Let's say I have this:

Menu 1 Menu 2 ---- Children 1 ---- Children 2 ---- Children 3 ---- Children 4 ---- Children 5 Menu3

The following is rendered:

Menu 1 Menu 2 ---- Children 5 Menu3

bmcclure commented 12 years ago

And just to help direct my troubleshooting, are you just using the menu() method of MenuBuilderComponent to define the entire menu, or are you building it from individual pieces?

Thanks!

Fuhrmann commented 12 years ago

I'm using this in my AppController:

// Load the menu model
$this->loadModel('Menu');
// The menu array
$menus = $this->Menu->loadSystemMenu();
// Build the menu with the menu plugin
$this->MenuBuilder->menu('main', $menus);
bmcclure commented 12 years ago

I found the issue, and it's working for me now in my tests with multiple child items.

When I was testing within MenuItem if there was already a child menu, I was checking $children instead of $this->children, so it was re-creating the child menu every time and overwriting any other children.

This should be all fixed now. Let me know your results. Thanks!

Fuhrmann commented 12 years ago

That was fast, thanks. I'm going to home now, and ASAP I'll take a look at the updated code.

Thanks!

Fuhrmann commented 12 years ago

Hey, Ben.

This is working great now too. Thank you.

bmcclure commented 12 years ago

No prob, glad to hear. Thanks for helping me squash this one!