【问题标题】:Array result of a function as options in Drupal select option函数的数组结果作为 Drupal 选择选项中的选项
【发布时间】:2016-04-26 11:20:46
【问题描述】:

我想使用函数的返回数组作为选择列表中的选项,使用 drupal 中的表单字段。

这里是选择框字段的代码。

$form ['user_details']['course'] = array(
          '#type' => 'select',
          '#title' => 'course:',
          '#page arguments' => array('get_course'),
          '#options' => $course,
);

这是我从中获取数组的函数。

function get_course() {
    $course = array();
    $query = db_select('mdl_course', '');
    $query->fields('fullname', array(''));
    $query->condition('category', 8);
    $result = $query->execute();
    $course = $result;
    return $course
}

【问题讨论】:

    标签: php arrays drupal-7


    【解决方案1】:

    只需调用函数:

    $form ['user_details']['course'] = array(
             '#type' => 'select',
              '#title' => 'course:',
             '#page arguments' => array('get_course'),
              '#options' =>  get_course(),
    
                );
    

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多