mehdi jalali
mehdi jalali

Reputation: 53

access global variable of drupal into another php files

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

Upvotes: 0

Views: 597

Answers (1)

Clive
Clive

Reputation: 36955

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

Upvotes: 1

Related Questions