Using locallib.php vs using classes

Re: Using locallib.php vs using classes

by Mark Johnson -
Number of replies: 3
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That's a good point. I believe that page is the current info.

A quick search of the wiki for "locallib.php" suggests that these pages need updating to reflect current best practice:

https://docs.moodle.org/dev/lib.php
https://docs.moodle.org/dev/Libraries_Organization
https://docs.moodle.org/dev/NEWMODULE_Documentation

I'll do a quick update of these page while I'm at it, any improvements on what I write are welcome!

In reply to Mark Johnson

Re: Using locallib.php vs using classes

by Richard Jones -
Picture of Plugin developers Picture of Testers

This might be something that could be added?

I have data handling functions and utilities for my sub-tables of an activity module (like saving and updating them). I want to put these in functions (classes?) if I feel they are too complex or long to go in the editing page. 

Are there naming conventions like all db handling methods go into one sub-folder (or page) and utilities in another? 

Or is that up to the individual developer just to use common sense?

In reply to Richard Jones

Re: Using locallib.php vs using classes

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you are going to use a subfolder, then, to avoid clashes with future core Moodle class namespaces (e.g. the 'task' and 'event' subfolders), you should create your subfolders inside 'local', e.g. myplugin/classes/local/blah - after that, you're free to do what you want (and note that the use of 'local' is not enforced, just encouraged).

Average of ratings: Useful (1)
In reply to Mark Johnson

Re: Using locallib.php vs using classes

by David Pesce -
Picture of Plugin developers

Any idea when the example github repo (https://github.com/moodlehq/moodle-mod_newmodule) will be updated to reflect how plugins should be developed?


I'd like to start working on an xapi/cmi5 activity module and am getting a bit lost in the Moodle docs.


P.S. I've got a background in documentation. If someone can point me to scratch notes and/or provide a tutorial via webconference (I'll pay), I can update the docs.

Average of ratings: Useful (1)