External function returning an array with undefined levels and undefined fields.

Re: External function returning an array with undefined levels and undefined fields.

by Lawrence Lagerlof -
Number of replies: 0

I found a workaround solution myself. I will left this here in case someone had had the same problem:

If you need to make a webservice function that returns and array with multiple, undefined levels:

In my webservice plugin at the main method public static function get_tree($rootid), after I build my tree, I don't return it, I simply print it:

header('Content-Type: application/json');
die(json_encode($my_tree));


And in my method public static function get_tree_returns(), I just return null.

It works like a charm, however be aware of this small issues:

  • The Moodle webservice documentation relies on the existence of the _returns() method. Returning null causes the method entry in documentation not show the returning values.
  • The moodlewsrestformat is ignored for this method. The returning format will be always json in this case.


Average of ratings: Useful (1)