0

With this callback code - is it possible to restrict url just to be example/page1 (2 arg) but not example/page1/321 or example/page1/abc/efg...?

// hook_menu example
function example_menu() {
 $items['example/page1'] = array(
'page callback'     => 'example_page1_callback',
'access callback'   => TRUE,
'type'              => MENU_CALLBACK,
 );
 return $items;
  }

 // hook_meny callback function
function example_page1_callback() {
 // please provide code within this function to turn these next three
  // variables into separate output variables for the template.
  $variable_to_print1 = 'Foo';
  $variable_to_print2 = 'Bar';
  $variable_to_print3 = array('bing', 'bang', 'bong');
  return;
 }
  • That's what the access callback can be used for. – Alfred Armstrong Nov 1 at 14:48
1

The easiest way would be within your code.

You could change your 'access callback' => TRUE, to a function e.g. 'access callback' => my_access_check,

And within that function you can have an if statement to detect if a 2nd arg existing and if it does return false which would provide an access denied

If you wanted to do a "page not found" or a redirect or something else then you could put this logic into your 'example_page1_callback' function

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.