views:

17

answers:

1

I'm using hook_menu to register new url so that accessing this url would return some data to ajax function. As title suggested, this url is not registered. How do I know that? I've tried typing this in address bar but, drupal, return main template only rather than the tests string that I created. I'm positive that my module is working for php issues error if I intentionally write wrong syntax. And, yes, I clear cache whenever I make changes. Here's the code -

function test_menu() {
$my_form['test'] = array(
    'title' => 'Test address',
    'page callback' => 'test',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
);

return $my_form;

}

function test(){ $a= "testing";

return $a;      

}

A: 

Drupal is returning the variable, but your code isn't exposing it. To see it, add the following line to the test() function before the return line:

drupal_set_message('Variable $a: ' . $a);

This will display the text and the variable value in the content area of the page, so that you know that Drupal is registering the path (and is running the test() function and can use its variables):

Variable $a: testing

If $a is an array, this will not display it's value, but only the type of the variable ('Array'). To see the elements of this array:

$a = array ('testing', 'element2', 'item3');

Use the PHP print_r() function to print an indented list of the array's elements. Enclose it in HTML pre tags to have the indentation line up nicely:

drupal_set_message('<pre>Array $a: ' . print_r($a). '</pre>');

This will output the array in this format:

Array
(
    [0] => testing
    [1] => element2
    [2] => item3
)
flamingLogos
I thought just returning the value that I wanted to use, would do the trick. Drupal works otherwise. Thanks a bunch.
Andrew
No problem. The test_menu() function returns a variable, but that's OK because the function that is building the menus and paths WANTS a variable back. But when the test() function runs (when someone goes to that path), Drupal is assembling the page and is looking for HTML to be returned.
flamingLogos