0

I want to access global variable of drupal (like user variable in drupal) into another php files I Create a new module for example test module. my test module have 3 files . test.info , test.module , main.php I want to use global variable of drupal into main.php as following code

global $user; please guide me how can i access this drupal variable in my page? thanks

1 Answer 1

1

If you want main.php to be separate from the Drupal system you'll have to Bootstrap Drupal in your custom file, but depending on what you're trying to do there may be an easier way.

If you're just trying to output some HTML/text without the Drupal theme then just implement a menu hook in your module and call exit() from your page callback. Something like this:

function mymodule_menu() {
  $items['path/to/page'] = array(
    'title' => 'Title',
    'page callback' => 'mymodule_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );
}

function mymodule_page() {
  // You have access to the full Drupal bootstrap here as normal
  global $user;

  $content = 'Some Content';

  echo $content;

  exit();
}
Sign up to request clarification or add additional context in comments.

Comments

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.