菜单

Typo3 session

2011年08月11日 - typo3

Using sessions
Sessions are a mechanism to carry user data (parameters) along the web site visit without having to post them over and over again. The data is available as long as the session is valid, usually until all browser windows are closed.

Since TYPO3 instantiates a session automatically, you can use this existing session to read/write data into it. However, you must first understand that sessions in frontend and backend are handled differently.

The routine on the other hand is always the same.

Recover your data from the session
Add values (possibly into an array that holds all the session data)
Save your data to the session

Backend
In backend modules, session data is retrieved like this:

$sessionData = $GLOBALS['BE_USER']->getSessionData('tx_myextension');

You can store your own data as follows:

$sessionData['somevalue'] = "Hello World";

To save the data to the session in the end:

$GLOBALS['BE_USER']->setAndSaveSessionData('tx_myextension', $sessionData);

Frontend
In frontend modules, sessions are handled slightly differently:

$sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_myextension_mykey');

Modify the data:

$sessionData['somevalue'] = "Hello World";

And save it to the session:

$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_myextension_mykey', $sessionData);
$GLOBALS['TSFE']->storeSessionData();

发表评论

电子邮件地址不会被公开。 必填项已用*标注