Instead of accessing the $_SESSION hash, as we do in most PHP
applications, we must use the global JSession object.
When we access session data, we provide the value name and, optionally, the
namespace. If we do not provide a namespace the default namespace, aptly named,
default is assumed. In this example, we retrieve the value of default.example:
$session =& JFactory::getSession();
$value = $session->get('example');
It is unusual when accessing the session in this way to use anything other than the
default namespace. That is why the second parameter in the get() method is not the
namespace, but the default value. In this example, we retrieve the value of default.
example, returning a value of 1 if the value does not exist:
$session =& JFactory::getSession();
$value = $session->get('example', 1);
The last parameter is the namespace. This example demonstrates how to retrieve a
value from a different namespace (someNamespace):
$session =& JFactory::getSession();
$value = $session->get('example', 1, 'someNamespace');
In addition to retrieving values, we can also set them.
Pages:
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259