官术网_书友最值得收藏!

Configuring Moodle

Moodle is a highly-configurable application, with many complex settings in many areas of its functionality. These settings can be modified by Moodle administrators through:

  • Direct code in the main config.php file
  • The mdl_config table via administrative code and interfaces
  • The mdl_config_plugins table via plugin administration

During program execution, all of the main configuration values are stored in the $CFG global variable. $CFG is a generic structure. Each configuration variable is an element of the $CFG structure. For example, the $CFG->theme contains the text name of your site's selected theme.

The elements of $CFG are loaded by direct assignment, and from values stored in the database mdl_config table. The primary point of direct assignment takes place in /config.php. Here, the initial, necessary configuration settings are made.

There are minimal assignments that must be defined in this file. You are prompted for these values when you install Moodle, and you can change them afterwards by editing this file. The minimal settings are as follows:

$CFG->dbtype = 'mysql'; // mysql or postgres7 (for now)
$CFG->dbhost = 'localhost'; // eg localhost or db.isp.com
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'username'; // your database username
$CFG->dbpass = 'password'; // your database password
$CFG->prefix = 'mdl_'; // Prefix to use for all table names
$CFG->dbpersist = false; // Should database connections be // reused?
$CFG->wwwroot = 'http://example.com/moodle';
$CFG->dirroot = '/home/example/public_html/moodle';
$CFG->dataroot = '/home/example/moodledata';
$CFG->directorypermissions = 02777;
$CFG->admin = 'admin';

There are other optional settings that can be made in this file. Review your /config-dist.php file to see all of these settings.

Historically, any configuration settings that did not have a UI available to set these were set via code statements in this file. These often include new, experimental features.

The remainder of the $CFG elements are set from the database. This is done through a call to the library function get_config (located in the /lib/moodlelib.php library file) from /lib/setup.php, which is included as the last action of config.php. The important thing to know about the function get_config is that it will not overwrite any $CFG setting that has already been set. This means you can overrule any database setting by hardcoding it into config.php. Also, config.php clears out the $CFG structure before it does anything else. This guarantees that nothing sets any configuration variables before config.php and setup.php.

Setting configuration variables

As a developer, you can set and use configuration variables for your functionality. You can set a configuration variable through the set_config function. The set_config function takes a name, a value, and an optional plugin name as arguments. The name becomes the element of the $CFG structure and the passed value becomes its value. Additionally, this will be stored into the database mdl_config table, so that it can be loaded on every program execution from then on. You can also specifically request a configuration variable at any time, by using the get_config function, but you won't need to, because it will be loaded into the $CFG structure once it has been set.

The one issue that you need to consider when creating your own configuration variable is that the variable name you choose must be unique. Your variable becomes meaningless if you choose one that already exists. As most customizations you will be developing are likely to be plugins (modules, blocks, and so on), Moodle provides an alternate way to store configuration variables that are plugin specific.

Plugin configuration variables are loaded into the plugin structure itself, rather than into the $CFG global structure. This means that the configuration variable name only needs to be unique to the plugin. Plugin configuration variables are stored in the mdl_config_plugin table, with the name of the plugin. They can be set and retrieved by using the same set_config and get_config functions as before.

Generally, configuration variables are set by using administration interfaces. Most of the Moodle configuration variables are set through the various settings pages in the Site Administration menu block, which is visible on the home page of your Moodle site. In future sections, you will learn how the plugins add their interfaces to this structure. The following screenshot displays an example of Moodle's Site Administration block:

Setting configuration variables
主站蜘蛛池模板: 奉贤区| 昔阳县| 宝应县| 松滋市| 云梦县| 社旗县| 大田县| 台东县| 旺苍县| 青浦区| 浏阳市| 田东县| 高陵县| 乌兰浩特市| 温宿县| 海宁市| 宣城市| 安泽县| 建湖县| 沈阳市| 石楼县| 陆丰市| 灵宝市| 巴彦淖尔市| 嘉义县| 峨山| 威远县| 新安县| 铁岭市| 巩留县| 郑州市| 和平区| 泰兴市| 陇西县| 永川市| 香河县| 临猗县| 东兴市| 上犹县| 台北县| 巍山|