Last active
August 29, 2015 14:02
-
-
Save cburyta/349e170466ebdb160d8c to your computer and use it in GitHub Desktop.
Drupal Hook Menu Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mymod_menu() { | |
$items = array(); | |
// the 3rd arg is a %, meaning its dynamic - in page and access arguments its the '2' value, based on 0/1/2 | |
// url parts are separated by /'s | |
// the first part is 0 | |
// the second is 1 | |
// the third is 2 (goes up from there) | |
$items['foo/bar/%'] = array( | |
'page callback' => 'mymod_foobar', | |
'page arguments' => array('static', 2), // these are always arrays | |
'access callback' => 'mymod_access', | |
'access arguments' => array(2), // these are always arrays | |
); | |
return $items; | |
} | |
// based on the menu hook above... | |
// if the url "/foo/bar/z" is visited then user will be denied access (permission denied) | |
// if the url "/foo/bar/crew" is visited then the user will be allowed to view the page | |
function mymod_access($dynamic_value) { | |
if ($dynamic_value == 'z') { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
// this is called with the arguments as defined in the hook_menu function page arguments | |
// | |
// if the url "/foo/bar/crew" is visited, this page will print 'static crew' | |
// if the url "/foo/bar/zoo" is visited, this page will print 'static zoo' | |
function mymod_foobar($static, $arg2) { | |
print $static; // based on the page callback, this always equals 'static' | |
print $arg2; // depending on the url, this will equal the 3rd part of the url (parts separated by /'s) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment