warning: Invalid argument supplied for foreach()
ScottBaetz - March 18, 2009 - 16:33
| Project: | JQuery menu |
| Version: | 6.x-2.3 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Jump to:
Description
Greetings,
I have read your documentation. Love the product, I just can't seem to discard the following warning..
I have removed all my modules and use the Garland theme. I still receive the error listed above, which points to
/sites/all/modules/jquerymenu/jquerymenu.module on line 193.
Can you please point me in the direction to self help.
thanks,
Scott

#1
I need more info. What pages does this happen on and have you check to make sure that the menus that you have enabled in the admin section are actually valid menus? The version 3 of this module, which is not out yet, has more checks to insure that menus are not loaded if they don't exist but in the 2x version you have to make sure on your own.
#2
I also receive this error. I've tested it in the Garland, Minelli and Bluemarine themes. I receive this on all my pages. I'm not sure what you mean by valid menus. They all point to existing content, I did not build them before the pages they link to.
Line 193 is:
foreach ($items as $item) {
PHP is not something I'm well versed in, but it looks like the array() of $items is not being populated prior to being evaluated.
#3
Hi Aaron,
Oh, this is a humbling moment. I deployed a fresh clean copy of Drupal and have found that it must be one of my modules. I'm going to try to narrow down the module that is causing the error. Once I do, I will post it here. Hoping, that you be able to glean out how to resolve the error.
So very sorry... as this is clearly in your documentation. Hopefully this will bring a smile to your face.
-- Scott
#4
I have had the same problem - a few times and I don't understand why?
After some time and some work I have found out the problem was connected with the improper value in the column [has_children] in [menu_links] table. Some records have value [1] there (that means - "I have children") while, in fact, there should be value [0] ("I don't have children").
The function "recursive_link_creator()" expects a list of children as argument, but has the problem when children menus was/were removed completely and improperly - no matter in which way: directly from the database via sql, or via some kind of functions in the modules. After removing the last child menu item, parent menu link should be set to 'not have children' but it's not done so.
So: there are two ways to remove the annoying warning:
1st.: Correct the wrong records in the database table (I've done so)
2nd.: Add some checks against empty
$itemsin the recursive_link_creator() before the line withfor each ($items as $item)(preferred, but my php skills aren't so good as I wish).#5
UniqID is rigth! for step 2 you only need to add
if (!empty($items)) {after
$i=0;and before
foreach ($items as $item) {and close the if with } before :
return $output;correct-me if i'm wrong please! it worked for me! great module by the way! :)
#6
Bad Menu Entries...
It's been a while since I addressed this issue, but through the process of elimination, I believe that this error occurs when you've removed menu items, and for whatever reason they are not 'cleaned' up. As mentioned in submission #4, I found that if I redeployed my site, content and all, in an orderly fashion with the modules I had been using, no errors.
But then over time the error began. I was like 'Oh No!'. Then I came back here and found #4 above. A quick look at the menu entries, through my database utility. I found that I had false entries. I remove them, the error goes away!
Cheers,
Scott
#7
This post is in the hopes of providing enough 'info' to duplicate the problem, or someone with more code experience than me to find the bug in the core module 'menu' where I believe it is (well one is).
I created this problem in D6.9, JQueryMenu 6.x-2.3 by using admin/build/menu-customize/navigation interface, clicking on a menu item's "edit" link, and using the pulldown "Parent item" and moving Menu item "Create Content" to a custom menu I made myself "Admin Site" some weeks ago. It also happened after I opened several tabs to edit other menu items to move them. I'm thinking this was a bad idea. I was thinking the mlid field would make it okay, but I did not know of the complexity of the table menu_links at the time. I am now.
Added Friday: Moving a non custom, Drupal supplied menu item, with the available link "reset" instead of "delete" may be what causes this to happen.
I made no attempt to duplicate the error. There are a lot of disabled, hidden (1,-1), menu items. The database table menu_links has a link_title of Categories, that does not display, with has_children=1 (it has a blank child, changing 1 to 0 did not fix the problem), as does Aggregate, with just one child of "Sources", and Blogs with child My Blogs. The menu has been extensively edited for weeks now. I moved a lot of menus out of Navigation. There are 182 table rows with menu=Navigation, including stuff I have never seen in Navigation on a web page (first time I ever looked at the table).
So, this is not likely a bug in JQueryMenu, but I am too new to Drupal to know where to report what is likely a core bug in module 'menu' which I only think displays the Admin pages. I hope someone can tell me where to report core module bugs in the future. (This URL does not exist http://drupal.org/project/menu and I did not find any menu item to report core bugs with - I got tired of looking). I'd find the bug myself and suggest a code change, if I knew where to report it, like I have the last two bugs I found.
Having to write code to handle corrupt data from other modules is a way of life with APIs. The code fixes in #5 worked for me, too. The right code is to not invoke function recursive_link_creator in the first place, as it avoids the overhead of the function call.
Jquery is good. I wish the +/- box would color via CSS. I'll change the png files.
#8
A solution that works for me, avoiding missing children, yet showing the
entire top level menu item links (which with the other posted solution
go missing - something to do with how corrupted my menu is...),
is adding the first line below and the bottom bracket.
if (!empty($item['below'])){
$nextlevel = recursive_link_creator($item['below'],$url_array);
if (!empty($nextlevel)) {
$classes[] = 'parent';
}
}
I restored a backup, and then experienced this issue again. It appears to happen
when the last child is (re)moved from the menu. I tried to manually fix the
table menu_links, but only ended up preventing Backup & Migrate module's
backup from working. I got a common error message about validation.