0

I'm displaying a multi-level menu in the footer of my site using:

$block = module_invoke('menu', 'block_view', 'main-menu');
          print render($block['content']);

Which is displaying correctly, however I am receiving this warning message:

Notice: Undefined index: main-menu in menu_block_view() (line 486 of /****/modules/menu/menu.module).

Any suggestions on how to suppress this message?

1 Answer 1

0

It is caused from the following line, executed from menu_block_view().

$data['subject'] = check_plain($menus[$delta]);

$delta is the value you pass as last argument to module_invoke().

It means there isn't any menu with that ID, or you misspelled the menu ID. Try with main_menu, for example.

2
  • Strange, it's what I thought, however the menu is actually being displayed as is. So I am getting the right content, but an error is being recorded anyways.
    – TweakItGuy
    May 5, 2017 at 15:34
  • For a notice like that, it is probable PHP is using a default value for that array index, such as an empty string for a string, or 0 for an integer. If you are seeing what you are expecting, it just means the default value assigned from PHP matches the value expected from the code. Not checking if an array index is defined is still a bad coding habit, though, even if the code is currently producing the expected result. (It could produce the wrong result in future.)
    – apaderno
    May 5, 2017 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.