drupal模块和php文件

时间:2012-02-03 12:11:47

标签: drupal drupal-6

我试图在drupal 6.x中创建一个加载php页面的测试模块。我制作了一个test.module和test.info文件,并放入.php页面。下面是test.module代码。但它不能在我的drupal_site / test上工作,我找不到页面。   

function test_perm() {
  return array('access test content');
}

function test_contents() {
    module_load_include('php', 'test', 'index');
}

function test_menu() {

  $items = array();

  $items['test'] = array(
    'title' => t('Test'),
    'description' => t('Test desc'),
    'page callback' => 'test_page',
    'access arguments' => array('access test content'),
    'type' => MENU_NORMAL_ITEM
    );

  return $items;
}

function test_page() {
   $page_array['test_arguments'] = array(
     '#markup' => test_contents(),
   );
   return $page_array;
}

1 个答案:

答案 0 :(得分:1)

我猜你的test_contents()会直接将HTML输出到页缓冲区吗?这不是Drupal的工作方式,它希望你建立一个字符串并在$ page_array变量中返回

test_contents()函数更改为返回字符串而不是输出,或将输出存储在临时缓冲区中并将其分配给字符串:< / p>

function test_page() {
  // Start your buffer
  ob_start();

  // Output into the buffer
  test_contents();

  // Save the result to a string and close the buffer
  $contents = ob_get_clean();

  $page_array['test_arguments'] = array(
    '#markup' => $contents,
  );
  return $page_array;
}