Globally available variables?

sambojambo - March 14, 2008 - 15:44

I'm sure that there's a simple way of doing this that I'm missing and I'm sure there must be a Drupal way. But where do I place variables that I want to have system wide access to? The setting.php file?

Many thanks in advance

Check out:

johsw - March 14, 2008 - 16:22

Returning system path?

sambojambo - March 15, 2008 - 08:21

Thanks johsw for the reply - but I don't think that's quite what I'm after. I know that this is very 'hackerish' but in Drupal 4.6 you can place a var in the settings.php file like so:

<?php
if(file_exists){
   
$local_dir = '/home/sambo/workspace/drupal';
}else{
   
$local_dir = '/home/production_server/public_html/my_site';
}
?>

and be able to access it in any of you modules like:

<?php
function do_something(){

    global
$local_dir;

   
$system_path = "$localdir/sites/all/modules/my_mod";
}
?>

I sure that there must be a tidier way of doing this. I suppose what I'm looking for is the correct way to return the 'base_path' so that I don't have to resort to the hacking above? My coding is a bit rusty at the moment - been out of it for a while :)

Returning system path? The Drupal way?

sambojambo - March 18, 2008 - 10:07

Just bumping this - as I'm sure that there's a straight forward 'Drupal way' of doing this. I need to be able to return the 'system path' so that I can map to files that my modules need. But obviously don't want to hard code this. I need away to return the system path for the machine that the site's running on?

There must be a Drupal Jedi out there to show me the way of the Drupal.

Returning a system path - the 'Drupal Way'

sambojambo - March 25, 2008 - 15:29

Bit of a self posting session here - but I hope it might be useful to some one else.

Solved the problem using drupal_get_path.

<?php
$module_name
= 'xmlload'; // Change this to your module name.
$path = drupal_get_path('module', $module_name);
?>

Returns the path to a system item (module, theme, etc.).
http://api.drupal.org/api/function/drupal_get_path/5

 
 

Drupal is a registered trademark of Dries Buytaert.