0
votes

I'm trying to create a test module in drupal 6.x that loads php pages. I made a test.module and test.info file and also put inside the .php page. Below is the test.module code. But it doesnt work on my drupal_site/test I get page not found.

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
Well for some reason it worked but the php page loads on top and the drupal starts right after. I want the page to load inside the content of drupal. - heav3n
Try retuning $content instead. The other syntax is for a form. - Dave

1 Answers

1
votes

I'll take a guess that your test_contents() outputs HTML directly to the page buffer? This isn't the way Drupal works, it expects you to build up a string and return that in your $page_array variable.

Either change your test_contents() function to return the string not output it, or store the output in a temporary buffer and assign that to a string:

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;
}