开发者

Drupal 7 Custom Module Error

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 :)


  • 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/%/%".


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


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,
....


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜