我想访问drupal的全局变量(就像drupal中的user变量)到另一个php文件中,我创建了一个新模块,例如test模块。我的测试模块有3个文件。test.info,test.module,main.php我想在main.php中使用drupal的全局变量,如下所示
请指导我如何在我的页面中访问这个$user变量?谢谢
发布于 2011-10-18 07:18:34
如果您希望将main.php从Drupal系统中分离出来,那么您必须在您的自定义文件中使用Bootstrap Drupal,但是根据您要做的事情,可能有一种更简单的方法。
如果您只是试图输出一些没有Drupal主题的超文本标记语言/文本,那么只需在模块中实现一个菜单钩子,并从页面回调调用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();
}https://stackoverflow.com/questions/7799582
复制相似问题