call()
Usage
call(name, parameters...)
Description
Calls the SchemaMethod
with the given name and returns the result. This method can be used to execute schema methods which are not associated with a type (so-called global schema methods).
- Useful in situations where different types have the same or similar functionality but no common base class so the method can not be attached there
- This method is particularly helpful in situations where one wants to create new instances of a type (because creating objects of type
X
is forbidden in custom methods on objects of typeX
)
Example
Calling the method methodName
${call('methodName', 'param1', 'value1', 'param2', 'value2')}
Code example of methodName
log('methodName called - Parameters are: ', retrieve('param1'), retrieve('param2'))
Note
- global schema methods are always run in a superuser context
- There are two reserved names for these methods:
onStructrLogin
andonStructrLogout
. If these methods exists, they will be called when a user logs in or out respectively. For these two methods Structr will provide the current user in a variable calleduser
. - Prior to this commit (Dec, 11th 2016) the parameters were passed numerically indexed instead of named. This meant that the above code example would have read
log('methodName called - Parameters are: ', retrieve('1'), retrieve('3'))
because the parameter names were also passed into the method.