7

I've got this menu hook below by which I'm sending two parameters to the function.

But in the function I am only receiving the first parameter.

Does any one know how to send and get multiple parameters using the Drupal menu system?

function drupal_menu(){
    $items = array();
    $items['drupal/%/%'] = array(
        'title' => t('Welcome to the Hello World Module'),
        'page callback' => 'drupal_page',
        'page arguments' => array(1,2),
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );
    return $items;
}


function drupal_page($arg1, $arg2) {    
    return drupal_json(array('mess1'=>$arg1,'mess2'=>$arg2));
}
batigolix
  • 1,674
  • 18
  • 20
Vikas Naranje
  • 2,350
  • 5
  • 30
  • 40

2 Answers2

8

You're already doing it exactly the right way, if it's not working try flushing your caches. It's possible they haven't been cleared since you added the second argument, and Drupal caches items return from hook_menu() so it doesn't have to be called on each page.

Clive
  • 36,918
  • 8
  • 87
  • 113
  • Thanks for your advise. But clearing the caches didn't help me. What interesting i found that you need to tell drupal core system that you have made changes in hook_menu, so drupal can track the path. What i've done first uninstall and re-installed the custom module (By doing that now drupal know what i'm doing) and it worked for me. – Vikas Naranje Sep 14 '11 at 07:06
1

You are on the right way anyway ... If it is not working for you, then try the following

function drupal_page($arg1, $arg2) {
  $arg1_new = arg(1) ; 
  $arg2_new = arg(2) ; 
  return drupal_json(array(
    'mess1'=>$arg1_new,
    'mess2'=>$arg2_new
    )
  );
}
batigolix
  • 1,674
  • 18
  • 20
maged adel
  • 794
  • 5
  • 11
  • After uninstalling and re-installing custom module my code started working. I'm looking to tried your code. Thanks for your advise. – Vikas Naranje Sep 14 '11 at 07:14