Hi,

I was wondering if it's possible to pass different arguments to a page. e.g my hook_menu looks like this:

$items['node/test/%arg1||%arg2'] = array(
'title' => 'test',
'load arguments' => array(2), /
'page callback' => 'drupal_test_page',
'page arguments' => array(test stuff),
'type' => MENU_CALLBACK,
);

and my test page looks like this:

function drupal_test_page($arg1 = NULL, $arg2 = NULL){
    if(isset($arg1)){
        //do stuff
    }elseif(isset(arg2)){
        //do some other stuff
    }
}

I understand the code above won't acutally work but I would be really interested in any methods to achieve the same results. If it's unclear what I mean just ask and I'll try to answer asap.

Thanks in advance,
Bouke

Comments

tashicoder’s picture

Its better to use two arguments.
First argument accepts the type(key) and second argument accepts the value.

<?php
$items['node/test/%/%'] = array(
	'title' => 'test',
	'load arguments' => array(2,3), 
	'page callback' => 'drupal_test_page',
	'page arguments' => array('test stuff'),
	'type' => MENU_CALLBACK,
);


function drupal_test_page($key = NULL, $value = NULL){
    switch ($key){
    	case 'somthing1':
    		//do something with $value
    		break;
    	case 'somthing2':
    		//do something with $value
    		break;
    }
}
?>

Or you can try out some other solutions too, but not the one you have written.

Bouke’s picture

Allright, thanks a lot. Seems like a smart solution. I thought about using two arguments but didn't know how to do it if only one is used. Smart idea to take one as argument and the other as value!

jaypan’s picture

Tashicoder is correct. The logic has to happen in the callback function, it won't happen in hook_menu().


Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.