I have a variable which holds some value. I need to get this variable value both in administrator and site. Where should I place the variable and how can I get the variable in components or everywhere?
Administrator and your front-end site are two different sites. To share information between them, you can use some persistent mechanism like below.
1) Store information in database tables and access using Joomla Dbo.
$cookies = JFactory::getApplication()->input->cookie; $cookies->set($name, $value, $expire, '/');
3) Store information in temporary file and access it wherever needed.
If you want to share any information within same application (either on site or admin), you can set it to Application and access it within same site in same request.
$app = JFactory::getApplication(); $app->set('some_variable', 'some_value'); ... $someValue = $app->get('some_variable');
If you want to access a variable across the requests but within same application, you can use JSession
$session = JFactory::getSession(); $session->set('some_variable', "some_value"); ... echo $session->get('some_variable');