Basic Durpal 7 Module Example

Public

mymodule.info file

Get raw version
text
  1. name = My Module Name
  2. description = This is what my module does... it is awesome!
  3. core = 7.x
  4. files[] = mymodule.module
  5. package = Awesomeness

mymodule.module file

Get raw version
php
  1. <?php
  2.  
  3. function MYMODULE_menu() {
  4. $items = array();
  5. $items['path/to/the/%node'] = array( // this automatically runs node_load
  6. 'title' => 'My cool title', // Optional. You don't need to use this.
  7. 'description' => 'This is the description', // Does not really do anything...
  8. 'page callback' => 'my_custom_function', // Function name to be called when this rought is used
  9. 'access arguments' => array('access content'), // Optional "permissions" used
  10. 'access callback' => 'user_is_logged_in', // Optional function for permissions. For granting to everybody simply use 'access callback' => TRUE,
  11. 'page arguments' => array(3), // The page arguments to be used. This returns arg(0) to the page callback function
  12. );
  13.  
  14. return $items;
  15. }
  16.  
  17. function my_custom_function($node) {
  18. // $node is already loaded.
  19. // Do what you want here and create a return $output;
  20. $output = $node->title;
  21. return $output;
  22. }
  23.  
  24. function my_cool_function() { // no function argument because 'page arguments' was not used in the hook_menu
  25. // Do what you want here and create a return $output;
  26. $output = 'The date is ' . date('M j, Y');
  27. return $output;
  28. }