Note:

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

Finding your way into the Moodle code

From MoodleDocs

This article is aimed at people totally new to Moodle development, who may, or may not, have previous programming experience. It is a few tips to help you get started with the mass of Moodle code.

Please feel free to add more tips here, but I think it is also good if we can keep this article quite short.

Developer documentation

If you have not already found it, the main source of developer documentation is Developer_documentation.

Finding a way in

For finding where to start, you need to know that when you are looking at, for example, http://moodle.org/mod/forum/discuss.php?d=82799, then the code for that is in /mod/forum/discuss.php, and you just need to follow through what it does.

It calls functions in the main Moodle libraries, and the three most important are:

  • lib/moodlelib.php - general stuff.
  • lib/weblib.php - things to do with output of HTML
  • lib/dmllib.php - things to do with getting data in and out of the database.

Understanding what you find

As you look at the code, it is often a good idea, to insert statements like

debugging('In function require_login');

or

print_object($course);

The second of these will print out a variable, showing you what it contains. Variable like $course are often objects with lots of fields. Seeing what they contain will help you understand what is going on. The first of these prints out whatever text you give it, and information about the sequence of function calls that the code took to get there. (It only work if you go to Admin -> Server -> Debugging, and turn the debug level to ALL or DEVELOPER.

Tools can help

Finally, it is helpful to have an editor that lets you jump around the code. For example, I like Eclipse, and if I hold down CTRL and click on the name of a function, it immediately jumps me to where that function if defined. Most good editors (including Emacs and vi/Vim) can do this. (Setting_up_Eclipse)

See also