You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

call_privileged()

Sibling method to call() except that this function runs the specified method in a superuser context.

Usage

call_privileged(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 type X)

Example

Calling the method methodName

${call_privileged('methodName', 'param1', 'value1', 'param2', 'value2')}

Code example of methodName

log('methodName called - Parameters are: ', retrieve('param1'), retrieve('param2'))

Note

  • There are two reserved names for these methods: onStructrLogin and onStructrLogout. 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 called user.
  • 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.

Search results for "call_privileged()"

call_privileged()

Calls the SchemaMethod with the given name and returns the result. This method is used to execute global schema methods (methods that are not associated with a type).

call_privileged(name [, key1, value1 [, ... ]] )
$.call_privileged(name [, map])

Business Logic

The third option to implement logic is to use a global schema method, especially when the logic is not bound to a specific type. Global schema methods can be called via REST using a special maintenance endpoint, scheduled for execution with a cron-like syntax or called from any scripting envrionment using the call() or call_privileged() functions.