1

I'm creating two pages with a custom the module. The first page makes an API call to create an XML object and then lists all objects. Each object contains 10 entries but i only display 3 of them. From here clicking on an object directs users to a module argument page.

Is there anyway for me to create an argument page that doesn't have 10 different entries in the URL?

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items = array();
  //general page
  $items['my_module'] = array(
    'title' => 'My Module List',
    'description' => 'My module list Page',
    'page callback' => '_my_module_page',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
      );
  //single event page
  $items['my_module/event/%/%/%/%/%/%/%/%/%/%'] = array(
    'page callback' => '_my_module_arguments',
    'page arguments' => array(2, 3, 4, 5, 6, 7, 8,9,10,11),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}
0

My suggestion is concatenating arguments by a dilemma (something like -) and in callback function explode them simply by Php Explode function.

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items = array();
  //general page
  $items['my_module'] = array(
    'title' => 'My Module List',
    'description' => 'My module list Page',
    'page callback' => '_my_module_page',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
      );
  //single event page
  $items['my_module/event/%'] = array(
    'page callback' => '_my_module_arguments',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function _my_module_arguments($args){
 $items = explode("-",$args); // you can use another dilemma instead -
  //$items[0] first arg
  //$items[1] second arg
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.