How To Use Zurmo Persistent Storage – ZurmoConfiguration

There are some cases where you want to use the same system variables for multiple access, which should be the same for all users. Sessions come to mind, but session variables are only defined for one user, contain different values from user to user, and only last as long as the browser session is alive. If you want to display the last update date, or use outbound email settings (when all users of the system use one smtp server for sending emails), sessions will not accomplish what you need.

Fortunately, there is a ZurmoConfigurationUtil class. Data saved using ZurmoConfig is serialized in the database (in the globalmetadata table, however, because RedBeanPHP ORM is used to access all data, you almost never need to write queries).

To store a variable using this method, and make it available to all users all the time, you need to develop two functions, one for saving and one for loading data. Using a simple variation, the two functions might look like this:

public static function getMyVar()
    $myVar = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'myVar')
    return $myVar;

public static function setMyVar($myVar = null)
    ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'myVar', $myVar);
    return true;

In the code above, the following two static functions from ZurmoConfigurationUtil were used:

ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'myVar')
ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'myVar', $myVar);

The first parameter in both functions is the name of the module where you define the variable, so you can use same variable name in different modules. If the variable is going to be used in multiple modules, use ‘ZurmoModule’, otherwise use the module name where the variable is defined/used.

The second parameter is the variable name.

If you want to save the variable value, the third parameter would be the value.

Leave a Comment