01

<?php

function mytracer_menu() {
$items = array();
$items['admin/config/mytracer'] = array(
'title' => 'My Tracer',
'description' => 'MY tracer des',
'access callback' => true,
'page callback' => 'mytracer_admin',
);
return $items;
}
//全局变量的使用
function mytracer_admin() {
global $base_path;
global $base_url;
global $user; $output = ''; $output .='<p>'. $base_path . '</p>';
$output .='<p>'. $base_url . '</p>';
dpm($user);
return $output;
}

02 ,永久变量的使用

function mytracer_admin() {

    //定义一个mytracer_setting1 为10
$var1 = variable_get('mytracer_setting1', 10);
$output = '';
$output .= '变量'. $var1; //把mytracer_setting1值加1
variable_set('mytracer_setting1', $var1+1); //删除mytracer_setting1变量 //variable_del('mytracer_setting1');
return $mytracer_setting1;
}

03 arg()函数的使用

function mytracer_admin() {

  // 使用 arg() 函數实例,返回一个数组

  $args = arg(); 

  $output = '';
$output .= '<p>Current url\'s arguments -> ' . implode(', ', $args); $output .= '<p> arg(1) = ' . arg(1); $output .= '<p> arg(1) in http://www.google.com/a/b/c = ' . arg(1, 'http://www.google.com/a/b/c'); $output .= '<p> arg(1) in admin/config/mytracer = ' . arg(1, 'admin/config/mytracer'); return $output;
}

04,drupal_set_messag()实例

function mytracer_admin() {
global $user; $s = format_string('User: "@username" has entered this page',
array('@username' => $user->name)); drupal_set_message($s);
drupal_set_message($s, 'status', false); return '';
}

05,t函数实例

function mytracer_admin() {
// 使用 t 函數示範 $txt = '<p style="color:red;">A String</p>'; $output = ''; // 以下這二個都叫做 title 的可翻譯字串,因為大小寫不同,其實是二個要翻譯的字串 $output .= '<p>' . t('Title');
$output .= '<p>' . t('title'); //!号直接正常显示
$output .= '<p>' . t('use ! as a placeholder: !str', array('!str' => $txt));
//@ % 过滤html显示 % 斜线重点
$output .= '<p>' . t('use @ as a placeholder: @str', array('@str' => $txt));
$output .= '<p>' . t('use % as a placeholder: %str', array('%str' => $txt)); return $output;
}

06,item_list()函数实例

/* mytraceer 模組的管理介面網頁
*
*/
function mytracer_admin() { // 使用 theme() 函數,並使用 item_list 版型化 global $user; $output = ''; $output .= theme('username', array('account' => $user)); /*
* 1. 這是簡單的寫法
*/
$title = 'An Item List'; $items = array();
$items[] = 'this is line 1';
$items[] = 'this is line 2';
$items[] = 'this is line 3'; // 使用 theme_item_list 時,需要三個資料 (items, title, type, attributes),利用 array 打包起來
$output .= '<p>' . theme('item_list',
array('items' => $items, 'title' => $title, 'type' => 'ol')); /*
* 2. 比較複雜的例子
* 第二列:增加了 class 與 id
* 第三列:增加了下一層的 list
*/
$items = array();
$items[] = 'this is a line';
$items[] = array('this is a line', 'class' => 'a-item', 'id' => 'line-2');
$items[] = array('this is a line', 'children' => array('c1', 'c2', 'c3')); // 使用 theme_item_list 時,需要三個資料 (items, title, type, attributes),利用 array 打包起來
$output .= '<p>' . theme('item_list',
array('items' => $items, 'title' => $title, 'type' => 'ul')); /*
* 3. 常用的方法
* 準備一個 $items 的 array, 並將 list 的各種元素打包起來
*/ // 變數 $items 我們準備提供給 theme('item_link, ...) 進行版型化的輸出
// 在這裡並未指定它的 type, 因此使用預設的 ul (unordered list)
$items = array(
'items' => array(
l('Manage User Accounts', 'admin/people'),
l('Manage Modules', 'admin/modules'),
l('Manage MyTracer', 'admin/config/mytracer'),
),
'title' => 'Useful Management Links',
'attributes' => array('class' => 'management'),
); // 這個 item_list 的例子,我們增加了 attributes 資料, 這個 attributes 是套用在 ul 或 ol 上面
$output .= '<p>' . theme('item_list', $items); return $output;
}

07。使用 theme() 函數,並使用 table 的版型化

/* mytraceer 模組的管理介面網頁
*
*/
function mytracer_admin() { // 使用 theme() 函數,並使用 table 的版型化 $output = ''; /*
* 1. 最簡單的 table 作法
*/ // table 要有 header, 如果某個欄位允許排序的話,要提供 'field' 屬性
$header = array('col 1', 'col 2', 'col 3', 'col 4'); // table 要有 row, 習慣上, 使用 $rows 變數, cell 中如果有其它屬性的話, 該 cell 以 array 方式來定義,
// 並將相關屬性打包進來
$rows = array(
array(
'Cell 11', 'Cell 12', 'Cell 13', 'Cell 14'
),
// Row with attributes on the row and some of its cells.
array(
'Cell 21', 'Cell 22', 'Cell 23', 'Cell 24'
)
); $items = array(
'header' => $header,
'rows' => $rows,
); $output .= '<p>' . theme('table', $items); /*
* 2. 帶有屬性旳 table 作法
*/ // table 要有 header, 如果某個欄位允許排序的話,要提供 'field' 屬性
$header = array('header 1', 'header 2', 'header 3', 'header 4'); // table 要有 row, 習慣上, 使用 $rows 變數, cell 中如果有其它屬性的話, 該 cell 以 array 方式來定義,
// 並將相關屬性打包進來
$rows = array(
// Simple row
array(
'Cell 1', 'Cell 2', 'Cell 3', array('data' => 'Cell 4', 'class' => 'highlight')
),
// Row with attributes on the row and some of its cells.
array(
'data' => array('Cell 1', 'Cell 2', array('data' => 'Cell 3,4', 'colspan' => 2)),
'class' => array('funky')
)
); $output .= '<p><p>' . theme('table', array('header' => $header, 'rows' => $rows)); /*
* 3. 常用的作法
*/ $output .= '<p>' . '<h3>General Table Usage</h3>'; $header = array('標題', '網址', '操作'); // 通常, rows 會由資料庫讀取資料後, 一列一列排出來, 還沒有介紹讀取資料庫之前,
// 我們先使用簡單的一一填入方法 $rows = array(); for ($i=1; $i<4; $i++) {
$node = node_load($i); // node_load(): 載入 id 為 $i 的內容節點 $row = array(); $row[] = $node->title;
$row[] = url('node/' . $i);
$row[] = l('編輯', 'node/' . $i . '/edit'); $rows[] = $row;
} $output .= theme('table', array('header'=>$header, 'rows'=>$rows)); return $output;
}

08.url

function mytracer_admin() {
global $user; $output = ''; $output .= '<p>' . '1. user 2 的網址是 ' . url('user/' . 2);
$output .= '<p>' . '2. 目前 user 的網址是 ' . url('user/' . $user->uid);
$output .= '<p>' . '3. 目前 user 的網址是 ' . url('user/' . $user->uid,
array('absolute' => true));
$output .= '<p>' . '4. 指向 user 1 的絕對網址,並且提供參數: ' . url('user/1',
array('absolute' => true, 'query' => array('key1' => 'this-value', 'key2' =>10)));
$output .= '<p>' . '5. 指向 google 的外部連結: ' . url('http://www.google.com');
$output .= '<p>' . '6. mytracer 模組的 help 說明在 ' .
url('admin/help', array('fragment' => 'mytracer'));
$output .= '<p>' . '7. 最後, 比較複雜的 url 作法所得到的結果:' .
url('user/' . $user->uid,
array('absolute' => true,
'fragment' => 'part1',
'query' => array('key1' => 'value1', 'key2' => 10),
)
); return $output;
}

09.watchdog

/* mytraceer 模組的管理介面網頁
*
*/
function mytracer_admin() { // 使用 watchdog() 函數 global $user; dpm($user); watchdog('mytracer', 'current user is @username, id = @id',
array('@username' => $user->name, '@id' => $user->uid)); watchdog('mytracer', 'current user is @username, id = @id',
array('@username' => $user->name, '@id' => $user->uid), WATCHDOG_NOTICE); watchdog('mytracer', 'current user is @username, id = @id',
array('@username' => $user->name, '@id' => $user->uid), WATCHDOG_NOTICE,
l('mytracer 管理', 'admin/config/mytracer')); return '';
}

10.hook_help

function mytracer_help($path, $arg) {
switch ($path) {
case 'admin/settings/mytracer':
return t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Use the settings below to customize the appearance of the menu.'); case 'admin/help#mytracer':
$output = '';
$output .= '<p>' . t('The administration menu module provides a dropdown menu arranged for one- or two-click access to most administrative tasks and other common destinations (to users with the proper permissions). Administration menu also displays the number of anonymous and authenticated users, and allows modules to add their own custom menu items. Integration with the menu varies from module to module; the contributed module <a href="@drupal">Devel</a>, for instance, makes strong use of the administration menu module to provide quick access to development tools.', array('@drupal' => 'http://drupal.org/project/devel')) . '</p>';
$output .= '<p>' . t('The administration menu <a href="@settings">settings page</a> allows you to modify some elements of the menu\'s behavior and appearance. Since the appearance of the menu is dependent on your site theme, substantial customizations require modifications to your site\'s theme and CSS files. See the advanced module README.txt file for more information on theme and CSS customizations.', array('@settings' => url('admin/settings/admin_menu'))) . '</p>';
$output .= '<p>' . t('The menu items displayed in the administration menu depend upon the actual permissions of the viewer. First, the administration menu is only displayed to users in roles with the <em>Access administration menu</em> (admin_menu module) permission. Second, a user must be a member of a role with the <em>Access administration pages</em> (system module) permission to view administrative links. And, third, only currently permitted links are displayed; for example, if a user is not a member of a role with the permissions <em>Administer permissions</em> (user module) and <em>Administer users</em> (user module), the <em>User management</em> menu item is not displayed.') . '</p>';
return $output;
}
}

drupal module 自定义的更多相关文章

  1. Filebeat Nginx Module 自定义字段

    Filebeat Nginx Module 自定义字段 一.修改/usr/local/nginx/conf/nginx.conf中 log_format access '$remote_addr - ...

  2. drupal 8 ——自定义权限

    在项目开发里面,我遇到了这么一个需求,就是对于node的title字段,编辑内容的角色不允许对title进行编辑.title字段是创建内容类型时自动生成的字段,不能在drupal8后台直接配置权限,所 ...

  3. Drupal Module Hooks

    Drupal is a Content Management System. Drupal is also deeply, deeply weird. While systems like Magen ...

  4. Maven Archetype 多 Module 自定义代码脚手架

    大部分公司都会有一个通用的模板项目,帮助你快速创建一个项目.通常,这个项目需要集成一些公司内部的中间件.单元测试.标准的代码格式.通用的代码分层等等. 今天,就利用 Maven 的 Archetype ...

  5. Drupal中自定义登录页面

    通过覆写template定义新的user_login表单来为自定义登录页面.方法: 1.  本站使用的主题是Rorty.来到\sites\all\themes\rorty,打开template.php ...

  6. spring-boot-关于module自定义jar包打包无法给其他module使用

    ####世界大坑: 如果仅是使用 <build> <plugins> <plugin> <groupId>org.springframework.boo ...

  7. Drupal模块的安装方法

    Drupal自身的安装很简单,新建一个数据库,然后根据安装提示一步一步做就OK了. 而Drupal可以通过安装各种模块来提供更多定制功能,这些模块的安装方法基本相同,一般来说,就是以下几步: 1) 从 ...

  8. Drupal Coder 模块远程命令执行分析(SA-CONTRIB-2016-039)

    转载请注明文章出处:http://www.cnblogs.com/magic-zero/p/5787181.html 起初看到这个漏洞的时候是在exploit-db上边.地址在这里:https://w ...

  9. pytorch Containers的Module部分

    参考:https://pytorch.org/docs/stable/nn.html Containers Module CLASS torch.nn.Module 所有神经网络模块的基类 你定义的模 ...

随机推荐

  1. mysq双主模式

    准备环境:服务器操作系统为RHEL6.4 x86_64,为最小化安装.主机A和主机B均关闭防火墙和SELINUX ,IP地址分别为192.168.131.129和192.168.131.130,MyS ...

  2. 关于SQL Server 2008添加用户映射问题 解决办法

    同事一直需要用触发器 但是之前的数据库没有dbo映射 无法添加 查阅了很多资料 不适合自己的问题 所以自己动手丰衣足食 特留下笔记 希望能给遇到相同问题的朋友一个解决的思路

  3. Unix时间戳与C# DateTime时间类型互换

    Unix时间戳最小单位是秒,开始时间为格林威治标准时间1970-01-01 00:00:00ConvertIntDateTime方法的基本思路是通过获取本地时区表示Unixk开始时间,加上Unix时间 ...

  4. 【WinHec启示录】透过Windows 10技术布局,谈微软王者归来

    每个时代都有王者,王者的成功,往往是因为恰逢其时地发布了一个成功的产品(具有里程碑意义,划时代的产品).Windows 95的成功标示着微软是PC时代的王者:WinXP的成功标示着微软是互联网时代的王 ...

  5. Docker学习笔记整理

    Docker接触有一段时间了,但是对于Docker的使用可以说是一点不会.现在要在Docker上部署基于Angular开发的页面.只能一点点积累查找的资料,顺手整理一下,方便后面的回顾. 其中用到的资 ...

  6. C#设计模式(9)——装饰者模式(Decorator Pattern)

    一.引言 在软件开发中,我们经常想要对一类对象添加不同的功能,例如要给手机添加贴膜,手机挂件,手机外壳等,如果此时利用继承来实现的话,就需要定义无数的类,如StickerPhone(贴膜是手机类).A ...

  7. Android Message里传送的数据[转]

    package org.hualang.handlertest; import android.app.Activity; import android.os.Bundle; import andro ...

  8. [ucgui] 对话框1——创建对话框

    >_<" 小工具和对话框的区别: 小工具可以创建并独立使用,因为它们本质上就是窗口.但是,通常需要使用对话框,它是包含一个或多个小工具的窗口. 对话框通常是一个窗口,它在出现时会 ...

  9. 最新QQ强制聊天代码,同时可判断好友关系

    QQ强聊虽然早就变成了一个传说,但现在依然可以实现. 小菜其实早就知道这个漏洞,但是一直没公布,前两天突然来兴致试了试,没想到漏洞依然存在. 然后小菜跑到了乌云漏洞报告平台举报漏洞,但没想到被腾讯鲁莽 ...

  10. Singleton模式和Mono-State模式

    类和实例 对于大多数的类,都可以创建多个实例.在需要和不需要时,创建和删除这些实例.该过程会伴随着内存的分配和归还. 同时,有一些类,应该仅有一个实例.该实例在程序启动/结束时被创建和删除. root ...