zoukankan      html  css  js  c++  java
  • 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的时候,就会获取系统里面保持的值。



  • 相关阅读:
    mysql数据库
    Mysql之sql语句操作
    mysql修改root密码的多种方法
    kvm虚拟化
    清华AIOps算法:KPI聚类
    有点扯的预测方法
    内网安全运营的逻辑体系架构
    SpringBoot定时消费Kafka消息
    kafka的consumer消费能力很低的情况下的处理方案
    Kafka_Kafka 消费者 偏移量 与 积压 查询脚本 kafka-consumer-groups.sh
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3144986.html
Copyright © 2011-2022 走看看