Hello,
I developing my plugin and adding an event on user update. I created events.php in db folder:
and observer.php in classes folder:
Hello,
I developing my plugin and adding an event on user update. I created events.php in db folder:
Firstly, did you update your plugin's version number (in version.php) after adding the observer to the events.php file (Moodle doesn't look at that file unless the version number has changed).
Secondly, if you want Moodle to find your observer class, then you need to namespace it correctly.
Start your overserver.php file with:
namespace local_myplugin;
(This assumes your plugin is a 'local' plugin within the local/ directory of your Moodle install and that it is called 'myplugin' - adjust the namespace to match your actual plugin).
Then make sure your class is called 'observer' (not user_observer) - i.e. make sure it matches the name of the file it is stored in.
Finally, update the $observers array to set the callback to '\local_myplugin\observer::updated' (i.e. to match the full namespaced name of your class) and update the version number in version.php, so that Moodle can find it.
A little bit of explanation - using the 'local_myplugin' namepace means that Moodle knows to look in 'local/myplugin/classes' to try and find the class you have referenced. Calling the class 'observer', means Moodle knows to look for a file 'observer.php' in that directory.
I think the developer documentation covers it in a lot more detail than I can write here: https://docs.moodle.org/dev/Automatic_class_loading
Short version: namespace the file (with the full plugin type + name), don't include the plugin name in the class name (the old version - no namespace, include the plugin name in the class, but not the filename - is strongly discouraged).