主页 » WEB开发 » Drupal学习(1)——菜单

Drupal学习(1)——菜单

2009-06-30添加留言

我们打算在菜单中添加一项mymenu,我们使用的是Drupal 5.x版本。

首先,在sites/all/modules/下新建一个目录mymenu,然后在其中建两个文件mymenu.info和mymenu.module。

mymenu.info的内容比较简单,只是模块的信息,给后台管理员看的。例如:
; $Id $
name = "MyMenu Module"
description = "Adds a menu to the navigation block."
version = "0.01"

重点在mymenu.module文件,入口函数是mymenus_menu,相当于参数配置。

function mymenu_menu($may_cache) {
	// Create an array to hold the menu items we'll define.
	$items = array();
	if ($may_cache) {
		// Define a static menu item.
		$items[] = array(
                     //...
		);
		$items[] = array(
                     //...
		);
	}
	return $items;
}

其中菜单项$items[]的常用参数有
title (string) 标题
path (string) URL路径,同时决定菜单的级别
callback (string) 点开URL页面时调用的函数名
callback params (array) 调用函数使用的参数,可选
access (bool) 权限 一般使用 user_access(‘some access tag’)的返回结果
你可能需要在此文件写一个函数,类似下面,告诉权限系统用哪些tag来作为本菜单的权限标记。

function mymenu_perm() {
	return array('some access tag');
}

type (int) 菜单的类型,有以下可选宏
MENU_CUSTOM_ITEM 默认值,普通菜单
MENU_CALLBACK 不显示在菜单中,但可以调用其URL
MENU_LOCAL_TASK 一个页面Tab,不能是顶级菜单
MENU_DEFAULT_LOCAL_TASK 默认页面Tab,不能是顶级菜单
weight (int) 同级菜单排序值

No related posts.

以上关联文章由 Yet Another Related Posts Plugin 提供支持。

相关文章

发表评论