• drupal 7 模块开发,hook_form


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

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

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

    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的时候,就会获取系统里面保持的值。



  • 相关阅读:
    HTB-靶机-Charon
    第一篇Active Directory疑难解答概述(1)
    Outlook Web App 客户端超时设置
    【Troubleshooting Case】Exchange Server 组件状态应用排错?
    【Troubleshooting Case】Unable to delete Exchange database?
    Exchange Server 2007的即将生命周期,您的计划是?
    "the hypervisor is not running" 故障
    Exchange 2016 体系结构
    USB PE
    10 months then free? 10个月,然后自由
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3144986.html
Copyright © 2020-2023  润新知