For custom module in drupal 7, we have create some file which is listed below.
Create your first "demo" Drupal 7 module with the following steps.
- Create a folder called demo in sites/all/modules/custom
- Create a demo.info file
- Create a template file page-demo.tpl.php in your theme directory
- Enable your module at http://domain.com/admin/build/modules
- Visit http://domain.com/demo
;$Id$ name = demo description = A demo module created by Ashish. package = Drupal 7 Development core = 7.x files[] = demo.module ;dependencies[] = autoload ;php = 5.2
The demo.module file
/**
* @file
* demo - Rick's demo module
* By Rick Smith of Cryptosmith
* This thing is too trivial to deserve protection
* through "intellectual property rights."
* This is my first attempt to write Drupal code
* and I probably don't have the format quite right.
**/
/* the menu hook - adds the path "/demo" to the site. */
function demo_menu(){
$items['demo'] = array(
'page callback' => 'demo_my_page',
'access arguments' => array('access content'),
);
return $items;
}
/* this code (noted in the callback above) creates the
* contents of the "demo" page */
function demo_my_page(){
$form = array();
$form['demo_my_name'] = array(
'#type' => 'textfield',
'#title' => t('My Name'),
'#default_value' => variable_get('demo_my_name', ''),
'#required' => TRUE,
);
$form['demo_about_me'] = array(
'#type' => 'textarea',
'#title' => t('About Me'),
'#default_value' => variable_get('demo_about_me', ''),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
$form['#submit'][] = 'system_settings_form_submit';
return $form;
}
The theme template file page-demo.tpl.php
print $content;
Note--Please keep php tags in your module file and tpl file.
No comments:
Post a Comment