Moodle Question:

How do I get/set configuration settings?

Tweet Share WhatsApp

Answer:

To get config values you would typically access the global $CFG object directly, which is automatically created by the core Moodle scripts. To set these "main" config values use set_config($name, $value). The values are stored in the Moodle "config" database table, but these functions take care of cacheing on your behalf, so you should always use these rather than fetching the records directly.

There is also a second table of config settings specifically for plugins ("config_plugin"). These are not automatically loaded into the $CFG object, so to fetch these you would use get_config($plugin, $name). To set them use set_config($name, $value, $plugin).

Download Moodle PDF Read All 27 Moodle Questions
Previous QuestionNext Question
How do the limits on uploaded files work?Can I move things in Moodle easily?