Where is $CFG defined?

Where is $CFG defined?

by PJ Henry -
Number of replies: 3
Just new to PHP and moodle. I know variables are defined on the fly and i think that $CFG is like a record of variables. I see that $CFG is made up of variables like $CFG->wwwroot which i know is defined in config.php

But in index.php there is a reference to $CFG->forcelogin (line 13) which isn't defined in config.php, couse/lib.php, mod/resource/lib.php or mod/forum/lib.php (all of which are referenced by index.php).

I reckon (ha!) that $CFG must have a skeleton somewhere (called 'config' for example) and then have:

<?php $CFG = new config; ?> or something similar.

If someone could point me in the right direction / correct me i'd be most grateful'

Thanks.
 

Average of ratings: -
In reply to PJ Henry

Re: Where is $CFG defined?

by Daryl Hawes -
Iain - $CFG is a global variable whose type is array.
These are usually stored in the prefix_config table for persistance.

To see the contents of config you can add some debug code to any page (index, or a new test.php type page)
global $CFG;
print_object($config);

Hope that helps
Average of ratings: Useful (1)
In reply to Daryl Hawes

Re: Where is $CFG defined?

by Mark Roggenkamp -

index.php pulls in (includes) config.php which includes lib/setup.php around line 163. setup.php loads the config vars in from the config table in the database into $CFG at around line 72.

Mark

Average of ratings: Useful (1)
In reply to Mark Roggenkamp

Re: Where is $CFG defined?

by PJ Henry -
Ahh!!

Cheers for the responses guys! Clears things up!

Cheers again,
Iain