访问drupal的全局变量到另一个php文件

时间:2011-10-17 21:08:37

标签: drupal variables global

我想访问drupal的全局变量(就像用户变量一样) drupal)到另一个php文件 我为示例测试模块创建了一个新模块。 我的测试模块有3个文件。 test.info,test.module,main.php 我想将drupal的全局变量用于main.php,如下面的代码

全球$用户; 请指导我如何在我的页面中访问这个drupal变量? 感谢

1 个答案:

答案 0 :(得分:1)

如果您希望将main.php与Drupal系统分开,则必须在自定义文件中Bootstrap Drupal,但根据您尝试执行的操作,可能会有更简单的方法。

如果您只是尝试输出一些没有Drupal主题的HTML /文本,那么只需在模块中实现一个菜单挂钩,然后从页面回调中调用exit()。像这样:

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();
}
相关问题