Wildcard Page Argument in hook_menu() not working

418 views Asked by At

I'm trying to create a pagination type menu item that would allow the user to see older/newer content. The wildcard would represent the multiplier that would set the range from which the content is culled. This is the array created within my hook_menu() implementation:

$items['cars/%'] = array(
    'title' => 'cars',
    'page callback' => 'cars_car_view',
    'page arguments' => 'page',
    'access callback' => TRUE,
);

and this is my page callback function:

function cars_car_view($page) {
    print $page;

    // Code
}

But when I print the $page variable, only "cars" is printed, rather than the number. I've read through the documentation on hook_menu, but can't seem to figure out what I'm doing wrong or what I should be doing instead. Any help?

2

There are 2 answers

1
Balaji On BEST ANSWER

You have to use array in page arguments. array(0) refers to cars array(1) refers to wildcard

$items['cars/%'] = array(
    'title' => 'cars',
    'page callback' => 'cars_car_view',
    'page arguments' => array(1),
    'access callback' => TRUE,
);
0
AjayNimbolkar On

If you want get argument from url you can used arg() function or drupal_get_query_parameters().