Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

What happens when you require config.php: Difference between revisions

From MoodleDocs
No edit summary
Line 1: Line 1:
Most scripts in Moodle start with the line
Most scripts in Moodle start with the line
<code php>
<code php>
require_once(dirname(__FILE__) . '/../../config.php');
require_once(__DIR__. '/../../config.php');
</code>
</code>
with an appropriate number of '../'s. This achieves two main things
with an appropriate number of '../'s. This achieves two main things

Revision as of 16:50, 14 June 2016

Most scripts in Moodle start with the line require_once(__DIR__. '/../../config.php'); with an appropriate number of '../'s. This achieves two main things

  1. It loads all the Moodle core library code.
  2. In initialises a lot of things like the database connection, the session, the current course, theme and language.

The most reliable way to find out exactly what is going on is to actually go and read the code for config.php, lib/setup.php and the library functions they call. However, the following diagram gives an overview of some of the most important points.

Moodle startup.png

That diagram was drawn looking at the Moodle 2.0 dev code, but it should be similar for most recent version. It is about to change a lot in 2.0 dev over the next few months.

Here is the same image as a .dia file that can be edited with the open source drawing program of the same name: File:Moodle startup.dia.

See also