【发布时间】:2011-03-22 18:21:35
【问题描述】:
我是 Drupal 新手,目前已经了解如何制作我的基本块和菜单。我还学了一些 jQuery(它很棒)。
我正在尝试将当前只是 a separate PHP script 的分页用户列表集成到 my new Drupal 7 site:
我正在尝试将其实现为 Drupal 菜单,以便我可以将其称为 http://preferans.de/top(分页偏移量为 0)和 http://preferans.de/top/100(以显示从第 100 个用户开始的用户列表):
function pref_menu() {
$items['top'] = array(
'title' => 'Weekly player rating',
'description' => 'Weekly player rating',
'page callback' => 'pref_top_callback',
'access callback' => TRUE,
'file' => 'pref.top.inc',
'file path' => drupal_get_path('module', 'pref'),
'type' => MENU_CALLBACK,
);
return $items;
}
我非常简单的 pref.top.inc 文件是:
function pref_top_callback($offset = 0) {
return array(
'pref_players_table' => array(
'#type' => 'markup',
'#markup' => pref_players_table($offset),
),
);
}
function pref_fetch_players($offset) {
/* FETCH MAX 20 RECORDS INTO AN ARRAY */
$players = array();
$result = db_query("
select u.id,
u.first_name,
row_number() OVER (order by m.money desc) as pos,
u.female,
u.city,
u.avatar,
m.money,
u.login > u.logout as online
from pref_users u, pref_money m where
m.yw=to_char(current_timestamp, 'IYYY-IW') and
u.id=m.id
order by m.money desc
limit 20 offset :offset
", array(':offset' => array($offset)),
array('fetch' => PDO::FETCH_ASSOC)
);
$players = $result->fetchAll();
/* PRINT THE ARRAY AS AN HMTL-TABLE */
$table = '<table>';
foreach ($players as $user) {
$table .= '<tr>';
$table .= sprintf('<td>%u</td>
<td><a href="/user.php?id=%s">%s</a></td>
<td>%s</td><td>%d $</td>',
$user['pos'],
$user['id'],
$user['first_name'],
$user['city'],
$user['money']);
$table .= '</tr>';
}
$table .= '</table>';
return $table;
}
这确实有效,我得到了一个 Drupal 页面,其中的 HTML 表格最多包含 20 行:
但我不知道如何使用the Datatables Drupal module。我已经成功下载并安装了它,正在查看它的源代码,但不知道从哪里开始。
请帮助我,如何从我的菜单功能中调用它?
谢谢! 亚历克斯
【问题讨论】:
标签: jquery drupal drupal-modules drupal-7 datatables