在Drupal中定义模块内的全局变量

pra*_*y00 1 drupal global-variables

我试图在我的模块中保存一个全局变量并从另一个函数访问它.我不想将它存储在$ _SESSION中,因为我需要这个变量应用程序.以下是我正在尝试的代码,但它根本不起作用.

  function popmeup_menu() {
    $items['example/feed'] = array(
    'title' => 'Example RSS feed',
     'page callback' => 'popmeup_page',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK
    );
    return $items;
  }

    function popmeup_page() {
      print variable_get($xmlt, "");
    }

    function popmeup_comment_insert($comment) {
      variable_set($xmlt,"xmltoreturn");
    }
Run Code Online (Sandbox Code Playgroud)

Mār*_*dis 5

要存储全局变量,请将其存储在$GLOBALS超全局中.

或者,也许您可​​以使用静态值.

$GLOBALS:http://php.net/manual/en/reserved.variables.globals.php

static变量:http://php.net/manual/en/language.oop5.static.php