Thursday, January 23, 2014

Setting up a global state variable Joomla

Sometimes it is necessary to maintain a state variable across the site.
For example, to check whether Jquery is already loaded in another custom built component or module.

Setting up a state variable

$app = JFactory::getApplication();
$app->setUserState( 'myvar', $myvarvalue );
$app->setUserState( 'com_yourcomponent.data', $yourvalue );

Retrieving a variable saved

$app = JFactory::getApplication();
$variable = $app->getUserStateFromRequest( "com_yourcomponent.data" );

No comments:

Post a Comment