0

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;
}
2
  • 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. Commented Feb 3, 2012 at 12:16
  • Try retuning $content instead. The other syntax is for a form. Commented Feb 4, 2012 at 2:27

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

First of all, thanks for your time. test_contents loads a .php file not HTML..i tried your solution though and now it doesnt load the php on top at all. Below that, in drupal site on the "content" it just says "Array"...dunno where that comes from

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.