Hi guys,
I have a question about the hook_menu function.
In my module i want to define a few URL's that take arguments, which i then use to filter data.
My menu hook looks like this
function clubinfo_menu()
{
$items = array();
//this is added for this current tutorial.
$items['klubber/%league/%klub/trup/%spiller'] = array(
'title' => t('Spiller'),
'page callback' => 'clubinfo_render_player',
'page arguments' => array('','',0),
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
$items['klubber/%league/%klub/%tab'] = array(
'title' => t('Info'),
'page callback' => 'clubinfo_render',
'page arguments' => array('','',''),
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
$items['klubber/%league/%klub'] = array(
'title' => t('Klub'),
'page callback' => 'clubinfo_render',
'page arguments' => array('',''),
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
$items['klubber/%league'] = array(
'title' => t('Liga'),
'page callback' => 'clubinfo_render',
'page arguments' => array(''),
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
$items['klubber'] = array(
'title' => t('Klubber'),
'page callback' => 'clubinfo_render',
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
return $items;
}
And i've defined these load functions
/* Path arguments loaders START */
function league_load($string){
return $string;
}
function klub_load($string){
return $string;
}
function tab_load($string){
return $string;
}
function spiller_load($string){
return $string;
}
/* Path arguments loaders END */
All my menu's call the function clubinfo_render, which atm just prints out it's function arguments, and looks like this:
function clubinfo_render($league,$klub,$tab)
{
print('$league: '.$league.'<br/>');
print('$klub: '.$klub.'<br/>');
print('$tab: '.$tab.'<br/>');
print('sizeof(func_get_args()) : '.sizeof(func_get_args()).'<br/>');
print_r(func_get_args());
}
My problem is that the arguments from the URLs aren't moved down to my clubinfo_render function.
For instance, if i call this URL http://domain.com/Klubber/JACK-JONES_LIGAEN i expect to get 'JACK-JONES_LIGAEN' as an argument in the clubinfo_render function, but i get nothing.
Caling this URL prints out this output:
$league:
$klub:
$tab:
sizeof(func_get_args()) : 3
Array ( [0] => )
Likewise i'd expect this URL http://domain.com/Klubber/JACK-JONES_LIGAEN/Bjerringbro-Silkeborg/info to suply my function with these arguments 'JACK-JONES_LIGAEN' , 'Bjerringbro-Silkeborg' and 'info'.
Caling this URL prints out this output:
$league:
$klub:
$tab:
sizeof(func_get_args()) : 3
Array ( [0] => [1] => [2] => )
Something must be wrong in my code, can anyone see where the error is, i'm lost?
Regards
Martin
Comments
page arguments
for passing the page arguments try using this code
$items['klubber/%league'] = array(
'title' => t('Liga'),
'page callback' => 'clubinfo_render',
'page arguments' => array(0, 1),
'access arguments' => array('access clubinfo content'),
'type' => MENU_CALLBACK
);
when you use array(0, 1) as in the above code it means that you are passing the arg(0), and arg(1).
so if your url is http://domain.com/Klubber/JACK-JONES_LIGAEN/Bjerringbro-Silkeborg/info
then you would need to use
'page arguments' => array(0, 1, 2, 3),
to fetch all the 4 values of Klubber, JACK-JONES_LIGAEN, Bjerringbro-Silkeborg, info
try this and let me know if it works
Hi Shreyas, Works like a
Hi Shreyas,
Works like a charm, thanks a bunch.
When i read the documentation for hook_menu, it wasn't clear that this is how it worked, thanks for clarifying :-)
Regards
Martin
Now that my URLs work, i'd
Now that my URLs work, i'd like to add metadata (description,keywords) to the , can i do that from a module aswell?
do u want to display that
do u want to display that data ??