Документация InstantCMS

для администраторов и разработчиков

Инструменты пользователя

Инструменты сайта


Universal Private Settings

The mechanism of universal private settings, UPS in short, allows to save the unique settings of each individual user. This is necessary when session and cookies are not suitable for storing such data because of various reasons. At the same time, you are not expected to store very important data, because it can be cleared once to optimize the database, use a custom table for such data instead.

A user ID and a unique key of this option is used to store the data. For example, your component is called “raduga” and you are going to save color, so the key will look like this: «raduga.color».

Saving Data

cmsUser::setUPS('raduga.color', 'blue');

Use the third argument with user ID to save it not for the current but any other user; this concerns all UPS methods:

cmsUser::setUPS('raduga.color', 'blue', 12);

Receiving Data

$color = cmsUser::getUPS('raduga.color');

Deleting Data

cmsUser::deleteUPS('raduga.color', 12); // we will delete the data of a user with the id 12

If you have just received new data and do not know if it has been saved before and whether it coinsides with the old one, then use the method that will check if:

  • the variable with the data is not empty
  • new data does not coinside with the old one and will refresh it if needed
  • will return actual data
$color = $this->request->get('color'); // null
$color = cmsUser::getUPSActual('raduga.color', $color); //  will return blue from the example above
$color = cmsUser::getUPS('raduga.color'); // will return blue
$color = $this->request->get('color'); // red
$color = cmsUser::getUPSActual('raduga.color', $color); // will return red and will save it in the DB
$color = cmsUser::getUPS('raduga.color'); // will return red 

Back to ‘’Different data storing” Section Contents

Back to Section Contents

en/dev/data/ups.txt · Последнее изменение: 28.03.2017 16:56 — murlysja