Drupal 7 如何将数据发送到自定义块内容

Drupal 7 如何将数据发送到自定义块内容,drupal-7,block,drupal-theming,Drupal 7,Block,Drupal Theming,我正在尝试创建一个模块,该模块将显示数据库中的一些最后条目。我想将last entry对象发送到模板文件guestbook-last-entries.tpl.php,如下所示 <p><?php render($title); ?></p> <?php echo $message; ?> 做预处理的人 function template_preprocess_guestbook_last_entries(&$variables) { $

我正在尝试创建一个模块,该模块将显示数据库中的一些最后条目。我想将last entry对象发送到模板文件guestbook-last-entries.tpl.php,如下所示

<p><?php render($title); ?></p>
<?php echo $message; ?>
做预处理的人

function template_preprocess_guestbook_last_entries(&$variables) {
  $variables = array_merge((array) $variables['entries'], $variables);
}
以及实现hook\u block\u视图的函数

function guestbook_block_view($delta = '') {
  switch ($delta) {
    case 'guestbook_last_entries':
      $block['subject'] = t('Last entries');
      $block['content'] = array();
      $entries = guestbook_get_last_entries(variable_get('guestbook_m', 3));
      foreach ($entries as $entry) {
        $block['content'] += array(
          '#theme' => 'guestbook_last_entries',
          '#entries' => $entry,
        );
      }
      break;
  }
  return $block;
}
从数据库获取数据的函数

function guestbook_get_last_entries($limit = 3) {
  $result = db_select('guestbook', 'g')
    ->fields('g')
    ->orderBy('posted', 'DESC')
    ->range(0, $limit)
    ->execute();
  return $result->fetchAllAssoc('gid');
}
但在这种情况下,我只显示一个条目。谁能告诉我如何解决这个问题,我应该如何构建$block['content']? 谢谢你

这里不行:

$block['content'] += array(
    '#theme' => 'guestbook_last_entries',
    '#entries' => $entry,
);
如果您需要一个数组作为结果,可能需要这样做:

// note that I replaced += with a simple = and added two brackets that will create a new element in that array $block['content']
$block['content'][] = array(
    '#theme' => 'guestbook_last_entries',
    '#entries' => $entry,
);
// note that I replaced += with a simple = and added two brackets that will create a new element in that array $block['content']
$block['content'][] = array(
    '#theme' => 'guestbook_last_entries',
    '#entries' => $entry,
);