Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 551
Jane Panda Avatar asked Mar 08 '11 23:03

Jane Panda


People also ask

How to display error message in Drupal 7?

To turn on the “Error Messages to Display”, go to the Administration menu, then go into Configuration > Development > Logging and errors (/admin/config/development/logging).

How to enable error log in Drupal?

You can show all errors by adding a few lines to your local testing site's settings. php: error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); In addition, navigate to Administration→ Configuration→ Development → logging and errors and select "All messages".

How to check Drupal error?

To view entries in Drupal's own internal log system (the watchdog database table), go to http://example.com/admin/reports/dblog. These can include Drupal-specific errors as well as general PHP or MySQL errors that have been thrown. Use the watchdog() function to add an entry to this log from your own custom module.


2 Answers

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

like image 163
Berdir Avatar answered Sep 29 '22 08:09

Berdir


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

like image 42
Mike Avatar answered Sep 29 '22 08:09

Mike