How to get several parameters sent via drupal hook_menu

I have this menu hook below, by which I send two parameters to a function.

But in the function, I get only the first parameter.

Does anyone know how to send and receive 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)); } 
+7
source share
2 answers

You already do it right, if it doesnโ€™t work, try flushing your caches. They may not have been cleared since you added a second argument, and Drupal caches the return from hook_menu () elements, so it does not need to be called on every page.

+8
source

Anyway, you're on the right track ... If it doesn't work for you, 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 ) ); } 
+1
source

All Articles