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;
}
Drupal is returning the variable, but your code isn’t exposing it. To see it, add the following line to the
test()function before thereturnline: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):If
$ais an array, this will not display it’s value, but only the type of the variable (‘Array’). To see the elements of this array:Use the PHP
print_r()function to print an indented list of the array’s elements. Enclose it in HTMLpretags to have the indentation line up nicely:This will output the array in this format: