


To create a module, please refer to "Drupal 7 Module Development and Creation"
If you want to support Chinese, the file format must be saved as UTF-8, NO BOM
---- --------------------------
hook_menu defines menu items and page feedback.
We need to replace the hook with our own module name. Here we create a my_first_module_menu() in the my_first_module.module file
<?phpfunction my_first_module_menu() { $items = array(); $items['mypage'] = array( 'title' => '第一个模块 ?? 页面', //菜单项的名称 'description' => '我的第一个模块页面', //当鼠标移动到菜单项,显示菜单的说明 'page callback' => 'my_page_view', //产生页面内容 'access callback' => TRUE, //所有人都能访问 'type' => MENU_NORMAL_ITEM, //菜单项显示类型 ); return $items;}function my_page_view() { $output = t('这是模块做的第一个页面。'); return $output;}
Note: Do not write ?>
at the end, clear the Cache, and then visit http://www.mysite. com/?q=mypage, you will see the following picture
(In fact, when you visit any http://www.mysite.com/?q=mypage/aaa/bbb, you will visit this page )
$items[] Path
Each $items corresponds to a path, written in [ ]. When the items use the same path, write the $items after the call. (Some articles say it is related to the parameter weight in $items. I tested that weight will not affect the order)
[ ] You can also use wildcards, for example: [node/%/edit] . For details, see: Wildcards in Pathssection in function hook_menu
title Required
Untranslated theme
title callback
Function that generates the theme. The default is t(). If you don't want translation, set FALSE (so we don't have to write 'title' => t('first form'))
title arguments
Parameters passed to t() or your custom function. Can be combined with path component
Reference: Menu item title and description callbacks, localization
description
Untranslated description.
page callback
When the user accesses the page path, call a function that displays the web page.
If not written, the callback function of the parent menu will be executed instead. In other words, $items['mypage'] and $items['mypage/child'] will execute the same content.
There is a special callback function drupal_get_form(), which will be developed later in Drupal 7 module to create, verify, and submit the form (Form). Specifically
page arguments
A string of parameter arrays passed to the page callback function. The above example is not used. Let’s modify it slightly:
'hello' is passed to $arg1 as a constant
1 represents the first layer behind the path mypage: when you access mypage/1/edit, return It is 1; if you access mypage/world/edit, the return is world
After modification, the complete code is as follows:
<?phpfunction my_first_module_menu() { $items = array(); $items['mypage/%/edit'] = array( //修改路径 'title' => '第一个模块 ?? 页面', 'description' => '我的第一个模块页面', 'page callback' => 'my_page_view', 'page arguments' => array('hello', 1), //添加参数 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, ); return $items;}function my_page_view($arg1, $arg2) { //添加参数传递 $output = t('这是模块做的第一个页面。'); $output .= '<br />' . $arg1 . ' ' . $arg2; //打印参数 return $output;}
Clear the Cache and then visit http://www.mysite.com/?q=mypage/world/edit. You will see the following picture
access callback
If you have permission to access this page, it must return TRUE, otherwise it will return FALSE (if not written, the default is FALSE). If false, the Access denied prompt will appear on the page.
type
Code describing the menu item properties. Many shortcut code constants are in menu.inc.
We use the default item MENU_NORMAL_ITEM, so you don’t need to write 'type' in $items => MENU_NORMAL_ITEM,
A few commonly used ones:
If you want to know more, you can open the /modules/menu/menu.modules file in the directory. Then combine it with http://www.yoursite.com/?q=admin/structure/menu/manage/navigation to help you understand
menu_name
If you don’t want to put this menu item under Navigation, you can specify it here. For example: 'menu_name' => 'main-menu', which will appear on the main menu together with Home
(more parameters will be improved slowly)
? ?

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools