Hi,
First all, sorry for my English. I'm not English spoken.
I'm working in a page with Elgg. In the page I have several web services published.
with exposed methods like this:
public static methodone($one, $two, $three, $four) {
...
}
When I define the fields for my method, I want that the default value for $two is null. But when I made this and send a petition for my web services without value for $two, the value of $three is set in $two, and the value of $four in $three.
I find a solution for this.
In the file https://github.com/Elgg/Elgg/blob/1.9/mod/web_services/lib/web_services.php I add in this line
https://github.com/Elgg/Elgg/blob/1.9/mod/web_services/lib/web_services.php#L154
this
<?php
$param = get_input($k); // Make things go through the sanitiser
// Always set a value
$sanitised[$k] = null;
if ($param !== null) {
$sanitised[$k] = $param;
} else {
// parameter was not passed so check for default
if (isset($v['default'])) {
$sanitised[$k] = $v['default'];
}
}
And in this line https://github.com/Elgg/Elgg/blob/1.9/mod/web_services/lib/web_services.php#L243
I add this:
//With this if the value not is sended put a null value
if (!isset($parameters[$key])) {
$serialised_parameters .= ", null " ;
continue;
}
I think that whit this few changes we can send for a parameter a null value and empty value "".
What do you think about this?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Juho Jaakkola@juho.jaakkola

Juho Jaakkola - 0 likes
- Daniel Ferrer@dferrerntx

Daniel Ferrer - 0 likes
- Steve Clay@steve_clay

Steve Clay - 0 likes
- Miloš Milutinović@knezmilos13

Miloš Milutinović - 0 likes
- Steve Clay@steve_clay

Steve Clay - 0 likes
- ihayredinov@ihayredinov

ihayredinov - 0 likes
- ihayredinov@ihayredinov

ihayredinov - 0 likes
You must log in to post replies.This has been reported here earlier: https://github.com/Elgg/Elgg/issues/4399
Could you do the same; change the order of the params and set the optional param as the last one?
This change might also help: https://github.com/Elgg/Elgg/issues/3512. The problem is that some members of the Elgg core team do not want to use time for the current web services plugin but would like to write a new one from a scratch.
(I also added some syntax highlighting to your code snippets.)
Hi,
In my example if $two, $three and $four aren't required, you can send or not this 3 values. So I don't know what values the users will send. Maybe $two and $four, maybe $four, maybe $three and $four...
Also I need to know if the value is empty "" or null because in some cases if the value is null I don´t change a field in my entities, and if the value is empty "", I set empty the field in my entity.
Whit this two changes you can maintain the actual behaviour, and don't need to think in the order of the parameters.
I have to wonder how many plugins rely on this behavior, so the problem is that even a "simple" fix must have extra documentation and wait until 3.0 at this point.
I'm afraid you're better off making a separate API method for now.
I'm having the same problem. This should really be fixed as soon as possible - it's one thing trying to stay backwards compatible, but this thing is just plain broken. Basically the whole thing with defining an associative array as given in http://learn.elgg.org/en/2.0/guides/web-services.html is completely wrong:
"Parameters expected by each method should be listed as an associative array, where the key represents the parameter name, and the value contains an array with
type
,default
andrequired
fields."As it stands, it works as a numerical array. I truly hope that no one would use this parameter "sliding" in their plugins. Because of this, I've been using optional parameters only for the last parameter. When I need more, I define that parameter as a String, to which I then pass a JSON and URL encoded string with multiple parameters. It works, but is tiring and adds unncessary code both to the backend and to my client application.
I agree it's broken. It's very old code by people no longer active with the project. Jump in on https://github.com/Elgg/Elgg/issues/3512 and maybe we can fix it.
Too bad that https://github.com/Elgg/Elgg/pull/8610 was buried with a promise of better RESTful future.
Maybe someone brave enough can reopen https://github.com/Elgg/Elgg/pull/8615. I really don't feel like revisiting the web services code after all the wasted effort.
Milos, not sure if you are aware of my hypeGraph https://github.com/hypejunction/hypegraph It might make your life a lot easier.