您绝对不需要为类似的东西创建任何数据库表。如果你想要一个基本的管理页面,你需要编写一个简单的模块。首先按照此快速入门指南设置基本模块。(注意:您不需要在 .install 文件中添加这些数据库查询)
启用模块后...
1) 在你的 mynewmodule.module 文件中,添加一个菜单项来告诉 Drupal 可以访问你的管理页面:
function mynewmodule_menu() {
return array(
'admin/settings/mynewmodule' => array(
'title' => 'My New Module',
'description' => 'Change settings for news display.',
'page callback' => 'drupal_get_form',
'page arguments' => array('mynewmodule_admin_form'),
'acces callback' => 'user_access',
'access arguments' => array('administer site configuration'),
),
);
}
2) 同样在您的 mynewmodule.module 文件中,添加一个函数来创建您刚刚在菜单项中引用的表单:
function mynewmodule_admin_form() {
$form = array();
$form['mynewmodule-on-off-switch'] = array(
'#type' => 'checkbox',
'#title' => t('Enable news links'),
'#description' => t('Control whether news items are linked to stories'),
'#default_value' => variable_get('mynewmodule-on-off-switch', 1),
);
return system_settings_form($form);
}
3) 清除缓存以使 Drupal 识别您的管理页面(每次更改 mynewmodule_menu() 时都需要清除)。你可以在这里清除它:admin/settings/performance
4) 访问 admin/settings/mynewmodule 以查看您的管理表单。它的工作方式是当你保存配置时,Drupal 会将一个名为“mynewmodule-on-off-switch”的变量(与表单中的数组键同名)保存到数据库中的变量表中。您可以使用 variable_get() 在任何地方获取此值。