Drupal 7 custom module error

I play 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 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?

Any performance improvements will also be appreciated :)

+6
drupal drupal-7
source share
5 answers
  • To allow access to everyone, you need to set the "access callback" to TRUE, not the "access to arguments". Also, are you sure that you do not have access definitions for this page?

  • Your coding style is atypical, it is difficult to read when you are used to its default method. See node_menu () for an example. At first I thought you were doing this on the old Drupal 5 path.

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

+21
source share

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');

+6
source share

I spent too much time trying to debug this ... when a simple answer was written:

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

when I should write:

 .... 'access callback' => TRUE, .... 
+3
source share

I believe you just need to create an array of "$ items" 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
source share

ultimately weird, but it worked "access arguments" => array (TRUE)

it looks like the access argument key is expecting a value to be returned in array format ('').

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

0
source share

All Articles