6
votes

I'm playing with a custom module in Drupal, but it gives me the following two warnings:

Warning: Invalid argument supplied for foreach() in menu_unserialize() (line 377 of /site/includes/menu.inc).
Warning: Invalid argument supplied for foreach() in menu_unserialize() (line 377 of /site/includes/menu.inc).

Here is the module's code:

<?php

function homepage_coords_menu(){
return array(//$items
    'homepage_coords/%node/%/%' => array(
        'page callback' => 'homepage_coords_ajax_callback',
        'page arguments' => array(1,2,3),
        'access arguments' => TRUE,
        'type' => MENU_CALLBACK,
    )
);
}

function homepage_coords_ajax_callback($nid=0,$x=0,$y=0){
    return 'nid:'.$nid.' x:'.$x.' y:'.$y;
}

?>

What can I do to fix these warnings?

Also any effeciency improvements would be appreciated :)

5
A pretty obvious point (albeit one that confused me for a whole 5 minutes) -- clear your cache after any changes to any implementation of hook_menu().aendra
I believe (not sure, it's been a while) you can actually disable the cache for testing. Still, a valid point.Jane Panda
You can make it so that Devel clears the theme cache on page reload, which is great for theming, but less great for module development (The menu cache is something different). I should write a browser plugin or module or something that is just a great big red button saying "CTFC!" that appears whenever you hover in the bottom corner of the screen.aendra

5 Answers

21
votes
  • To allow access to all, you need to set 'access callback' to TRUE, not 'access arguments'. Also, are you really sure that you don't have an access definitions for that page?

  • Your coding style is untypical, this hard to read when you are used to the default way of doing it. See node_menu() for examples. I initially thought you were doing it in the old Drupal 5 way.

  • It looks like the first argument is a node, I suggest you use %node then, the menu system will then automatically load the node and only call your page callback if the argument is a valid node id. key would look like this then: "homepage_cords/%node/%/%".

6
votes

I ran into this error because I was passing a string to "page arguments" instead of an array.

$items['page arguments'] = array('module_my_form');

3
votes

I wasted too much time trying to debug this... when the simple answer was that had written:

...
    'access arguments' => TRUE,
...

when what I should have written was:

....
    'access callback' => TRUE,
....
0
votes

I believe you simply need to make the "$items" array like this:

function homepage_coords_menu(){
    $items['homepage_coords/%/%/%'] = array(
        'page callback' => 'homepage_coords_ajax_callback',
        'page arguments' => array(1,2,3),
        'access arguments' => TRUE,
        'type' => MENU_CALLBACK,
    );
    return $items;
}
0
votes

ultimately weird but this worked 'access arguments' => array(TRUE)

seems like the access argument key expects the value returned in the array('') format.

before this only adding : "'access arguments' => TRUE, " worked for me !!! still trying to find the reason behind this weird behavior posting just in case it helps someone.