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: Difference between revisions

From MoodleDocs
(→‎See also: put intro to moodle programming at top)
m (→‎See also: Remove the link to the outdated course at dev.moodle.org (which is going to be shut down))
(7 intermediate revisions by 7 users not shown)
Line 19: Line 19:
==Understanding what you find==
==Understanding what you find==


As you look at the code, it is often a good idea, to insert statements like  
As you look at the code, it is often a good idea, to insert statements like
<code php>
  debugging('In function require_login');
  debugging('In function require_login');
</code>
which will print the message above if it gets far enough so you know the code has not stalled before there, or
which will print the message above if it gets far enough so you know the code has not stalled before there, or
  print_object($course);
  print_object($course);
which will print out a variable, showing you what it contains.  
which 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 works if you go to ''Administration > Server > [[Debugging]]'', and turn the debug level to ALL or DEVELOPER.)
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 works if you go to ''Administration > Server > [[:en:Debugging|Debugging]]'', and turn the debug level to ALL or DEVELOPER.)


==Tools that can help==
==Tools that can help==


*'''Eclipse''', for instance helps finding function definitions. You can hold down CTRL and click on the name of a function, it immediately jumps you to where that function is defined. ([[Setting_up_Eclipse]])
*'''Eclipse''', for instance helps finding function definitions. You can hold down CTRL and click on the name of a function, it immediately jumps you to where that function is defined. ([[Setting_up_Eclipse]])
*'''Netbeans'''
*'''Sublime 2'''
*'''Emacs'''
*'''Emacs'''
*'''Vim'''
*'''Vim'''
Line 37: Line 41:


==See also==
==See also==
* [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming] a course at dev.moodle.org
 
* First posted at http://moodle.org/mod/forum/discuss.php?d=82799#p366264
* [[Development FAQ]]
* [[Developer_documentation]]
* [[Developer_documentation]]
* [[Overview]]
* [[Overview]]
* [[ctags]]
* [[ctags]]
* [http://blog.danpoltawski.co.uk/archives/2009-05-Secrets-of-Learning-Moodle-Development!.html "Secrets of Learning Moodle Development!"] by Moodle core developer [[User:Dan Poltawski| Dan Poltawski]]
* [http://blog.danpoltawski.co.uk/2009/05/secrets-of-learning-moodle-development "Secrets of Learning Moodle Development!"] by Moodle core developer [[User:Dan Poltawski| Dan Poltawski]]
* http://www.slideshare.net/tjh1000/a-basic-introduciton-to-the-moodle-architecture-5442122
* [http://www.slideshare.net/tjh1000/a-basic-introduciton-to-the-moodle-architecture-5442122 A basic introduction to the Moodle architecture] by Moodle core developer Tim Hunt
* [http://www.aosabook.org/en/moodle.html The Architecture of Open Source Applications: Moodle] by Tim Hunt

Revision as of 09:02, 19 June 2017

This article is aimed at people totally new to Moodle development and have some PHP experience, if you don't have that experience please visit PHP for novices. 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');

which will print the message above if it gets far enough so you know the code has not stalled before there, or

print_object($course);

which 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 works if you go to Administration > Server > Debugging, and turn the debug level to ALL or DEVELOPER.)

Tools that can help

  • Eclipse, for instance helps finding function definitions. You can hold down CTRL and click on the name of a function, it immediately jumps you to where that function is defined. (Setting_up_Eclipse)
  • Netbeans
  • Sublime 2
  • Emacs
  • Vim
  • TextMate

See also Developer documentation#Tools and Category:Developer tools.

See also