You are here

drupal 路径归纳

1. $base_url: 是globals.php文件里定义的全局变量,返回访问网站的根目录, 详见http://api.drupal.org/api/drupal/developer%21globals.php/global/base_url/7
注:$base_url 返回的路径后面不带/,所以在拼接url的时候要注意加上,如:
$link = $base_url . '/node/add';
?>

2. drupal_get_path('module', 'custom')

current theme
drupal_get_path('theme',$GLOBALS['theme'])

frontend default theme
$theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));

3. path_to_theme()
http://api.drupal.org/api/drupal/includes%21theme.inc/function/path_to_t...
function path_to_theme() {
global $theme_path;

if (!isset($theme_path)) {
drupal_theme_initialize();
}

return $theme_path;
}

notes: I used HOOK_theme() in my module to provide a tpl. When calling path_to_theme() in said tpl it returned the path to the module, not the enabled theme.

4. $GLOBALS : 引用全局作用域中可用的全部变量
http://php.net/manual/zh/reserved.variables.globals.php

If you are using views, then it is better to use $GLOBALS to access both values.

Otherwise $base_url came blank to me.

print $GLOBALS['base_url'] . $GLOBALS['base_path'];

5. drupal_lookup_path('alias',"node/".$data->nid);
http://data.agaric.com/get-complete-base-url-drupal-site

6. $base_path,$base_root
http://api.drupal.org/api/drupal/globals/7
最保险的方式是这样
global $base_root,$base_path;
$link = $base_root.$base_path.'node/2222'; 这样即避免了$base_url缺少结尾的/问题,又能适应当drupal站点放在域名下的子目录的问题,如果www.example.com/mysite这样的drupal根目录

7. base_path() == $base_path
function base_path() {
return $GLOBALS['base_path'];
}
如果drupal所在目录是根目录,那么则会返回‘/’,如果不是,则返回drupal的根目录加结尾斜杠,如: localhost/drupal-xxx/

8. 当前路径
url(current_path(), array('absolute' => TRUE))

User login