因为不是系统学习,只能把每天自己学习到的东西零碎的记录下来。

一来方便自己记忆,二来可供大家查阅。

后续有精力再去做进一步的整理。

1 开发一个模块分为有下面几个文件

hook.admin.inc

hook.info

hook.install

hook.module

这里hook可以替换成你开发模块的名字

admin.inc文件,我感觉是drupal中admin用户的菜单中的选项。

module这个我现在没有完全弄明白。

2 admin.inc文件解析

看下面的代码

function videoads_settings_form() {
$form = array();
$form['adserver'] = array(
'#type' => 'fieldset',
'#title' => t('Adserver configurations'),
'#collapsible' => TRUE,
);
$form['adserver']['openxvideoads_openxurl'] = array(
'#type' => 'textfield',
'#title' => t('Openx Server'),
'#required' => TRUE,
'#description' => t('url of the Openx Server.'),
'#default_value' => variable_get('openxvideoads_openxurl', 'http://www.alamosa.tv/openx-2.8.2-rc14'),
);
$form['adserver']['openxvideoads_rtmpurl'] = array(
'#type' => 'textfield',
'#title' => t('RTMP Server'),
'#required' => TRUE,
'#description' => t('url of the RTMP Server.'),
'#default_value' => variable_get('openxvideoads_rtmpurl', 'www.alamosa.tv:1935'),
);
return system_settings_form($form);
}

这里解释一下:

参考系统的api, 这个属于hook_form

展现一个表格

表格的类型有fieldset(表头),textfield(文字)

这里解释两个函数:

varibale_get('param','default)  和 system_setting_form一般结合使用

varibale_get第一次会获取默认值,system_setting_form提供一个确认按钮,确认之后,就将保持到系统变量里面,下一次的用varibale_get的时候,就会获取系统里面保持的值。

04-26 16:22
查看更多