Kin
Kin

Reputation: 4596

Is it possible to set user parametr in joomla without session?

The default JUser::setParam() method sets parameters only to the session. Is is possible somehow to store parameters not in the session, that they would be always available? I also found in users table field params, which stores some parameters for current user, but don't know how to add data there...

Upvotes: 0

Views: 972

Answers (2)

Dmitrijs Rekuns
Dmitrijs Rekuns

Reputation: 543

Have you tried to save the object after adding your param?

$user = JFactory::getUser();
$user->setParam($key, $value);
$user->save;

Upvotes: 1

Mallard
Mallard

Reputation: 308

An easy and comfortable approach would be to use the popular Community Builder Extension which lets you define custom user fields in the administrator backend. It has an API to obtain the CB User Object and to write and read those fields which get stored in the DB as opposed to the session. Simple example without knowing your Joomla/CB version (works with Joomla 2.5 and CB 1.8) and the place (site, admin, external) where this should be executed (assuming your parameter is named customParam and the user id is 42):

cbimport( 'cb.field' ); 
$mosCbUser = CBUser::getUserDataInstance(42);

// read value
$customParameter = $mosCbUser->customParam;

// write value 
$mosCbUser->customParam = 'newnew';
$mosCbUser->store();

/* write value to DB directly with optional boolean third parameter 
specifing whether to trigger the user update plugins 
like onBeforeUserUpdate or onAfterUserUpdate
*/
$mosCbUser->storeDatabaseValue('cb_adresse', 'new address', false);

be sure to be in CB plugin context, if not already the case, include e.g. like

global $_CB_framework, $_CB_database, $ueConfig;
$app  = JFactory::getApplication();
include_once( $app->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );

Upvotes: 0

Related Questions