1

データベースに保存したデータから、各行にチェックボックスが付いたテーブルを生成したいDrupal6モジュールに取り組んでいます。テーブルは正常に生成されていますが、チェックボックスはテーブルに表示されていませんが、代わりにノードIDがテーブルの下に配置されています。以下のスクリーンショットを参照してください。

drupalチェックボックス

「21」は「TestQuestion01」のノードID、「19」は「TestQuestion02」のノードIDです。

私が使用しているコード(はい、それはすべて理想的ではないテーマ関数にあります。チェックボックスの問題が解決されたら、ものを移動することを計画しています):

function theme_qt_assignment_questions_table($form) {
   // Get the questions from the database
   $db_results = db_query('SELECT {qt_questions}.nid, title, lesson, unit FROM node INNER JOIN {qt_questions} on {node}.nid = {qt_questions}.nid WHERE lesson = %d AND unit = %d', 
                     $form['#lesson'], $form['#unit']);

  // Define the headers for the table
  $headers = array(
    theme('table_select_header_cell'),
    array('data' => t('Title'), 'field' => 'title'/*, 'sort' => 'asc'*/),
    array('data' => t('Lesson'), 'field' => 'lesson'),
    array('data' => t('Unit'), 'field' => 'unit'),
  );

  while($row = db_fetch_object($db_results)) {
    $checkboxes[$row->nid] = '';

    $form['nid'][$row->nid] = array(
      '#value' => $row->nid
    );
    $form['title'][$row->nid] = array(
      '#value' => $row->title
    );
    $form['lesson'][$row->nid] = array(
      '#value' => $row->lesson
    );
    $form['unit'][$row->nid] = array(
      '#value' => $row->unit
    );
  }

  $form['checkboxes'] = array(
    '#type' => 'checkboxes',
    '#options' => $checkboxes,
  );

  // Add the questions to the table
  if(!empty($form['checkboxes']['#options'])) {
    foreach(element_children($form['nid']) as $nid) {
      $questions[] = array(
        drupal_render($form['checkboxes'][$nid]),
        drupal_render($form['title'][$nid]),
        drupal_render($form['lesson'][$nid]),
        drupal_render($form['unit'][$nid]),
     );
    }
  } else {
    // If no query results, show as such in the table
    $questions[] = array(array('data' => '<div class="error">No questions available for selected lesson and unit.</div>', 'colspan' => 4));
  }

  // Render the table and return the result
  $output = theme('table', $headers, $questions);

  $output .= drupal_render($form);
  return $output;
}
4

1 に答える 1

0

問題を単純化しようとした私の試みは、実際には問題でした。つまり、hook_themeですべてを実行するのは正しくありません。むしろ、データベースから情報を取得してチェックボックス配列を作成し、そのようにhook_formで呼び出す関数を定義しました。

$form['questions_wrapper']['questions'] = _qt_get_questions_table($node->lesson, $node->unit);

この関数(_qt_get_questions_table())の最後に、すべてをテーブルに配置するテーマ関数を指定します。

  $form['#theme'] = 'qt_assignment_questions_table'; 

私はまだDrupalに慣れていないので、この説明は同じ問題を抱えている人にとっては最善ではないかもしれませんが、うまくいけば役立つでしょう。

于 2012-05-13T03:04:12.557 に答える