Brian Crawford
Brian Crawford

Reputation: 63

Wildcard Page Argument in hook_menu() not working

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?

Upvotes: 1

Views: 417

Answers (2)

Balaji
Balaji

Reputation: 990

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,
);

Upvotes: 4

AjayNimbolkar
AjayNimbolkar

Reputation: 36

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

Upvotes: 0

Related Questions