Typo3 Extensions programmieren - Snippets: Unterschied zwischen den Versionen
| Zeile 27: | Zeile 27: | ||
$GLOBALS["TSFE"]->fe_user->setKey("ses","$data", "$zustand"); | $GLOBALS["TSFE"]->fe_user->setKey("ses","$data", "$zustand"); | ||
$GLOBALS["TSFE"]->fe_user->storeSessionData(); | $GLOBALS["TSFE"]->fe_user->storeSessionData(); | ||
| + | 14.1. Storing user-data or session-data | ||
| + | |||
| + | Userdata => Eingeloggter User. Kein Zugriff mehr wenn ausgeloggt. | ||
| + | |||
| + | Session data => Jeder User. Eingeloggt oder nicht. Daten sind an die "browsing-session" gebunden und nicht an die user-id. Bleibt erhalten bis der Browser geschlossen wird. | ||
| + | |||
| + | Default expire-time of 24 hours. | ||
| + | |||
| + | === Funktionen === | ||
| + | $GLOBALS["TSFE"]->fe_user->getKey(type, key) | ||
| + | |||
| + | "type" is either "'''user'''" or "'''ses'''", which defines the data-space, user-data or session-data | ||
| + | |||
| + | "key" is the "name" under which your data is stored. This may be arrays or normal scalars. | ||
| + | |||
| + | Note that the key "recs" is reserved for the built-in "shopping-basket". As is "sys" (for TYPO3 standard modules and code) | ||
| + | |||
| + | '''Example:''' | ||
| + | <pre> | ||
| + | if ($GLOBALS["TSFE"]->loginUser){ | ||
| + | $myData = $GLOBALS["TSFE"]->fe_user->getKey("user","myData"); | ||
| + | } else { | ||
| + | $myData = $GLOBALS["TSFE"]->fe_user->getKey("ses","myData"); | ||
| + | } | ||
| + | </pre> | ||
| + | This gets the stored data with the key "myData" from the user-data, but if no user is logged in, it's fetched from the session data instead. | ||
| + | |||
| + | $GLOBALS["TSFE"]->fe_user->setKey(type, key, data) | ||
| + | |||
| + | "type" is either "user" or "ses", which defines the data-space, user-data or session-data | ||
| + | |||
| + | "key" is the "name" under which your data is stored. | ||
| + | |||
| + | Note that the key "recs" is reserved for the built-in "shopping-basket". As is "sys" (for TYPO3 standard modules and code) | ||
| + | |||
| + | "data" is the variable, you want to store. This may be arrays or normal scalars. | ||
| + | |||
| + | '''Example:''' | ||
| + | <pre> | ||
| + | $myConfig["name"] = "paul"; | ||
| + | $myConfig["address"] = "Main street"; | ||
| + | $GLOBALS["TSFE"]->fe_user->setKey("ses","myData", $myConfig); | ||
| + | </pre> | ||
| + | |||
| + | This stores the array $myConfig under the key "myData" in the session-data. This lasts as long as "paul" is surfing the site! | ||
Version vom 1. August 2008, 06:15 Uhr
Templates
Template Code holen
function getTemplateCode($mySubpart){
$tsTemplateFile = $this->conf['templateFile'];
// Wenn Flextemplate dann code aus diesem, sonst aus TS
$this->flexConf['template'] ? $templateCode = this->cObj->fileResource("uploads/tx_".$this->extKey."/".$this->flexConf['template']) : $templateCode=$this->cObj->fileResource($tsTemplateFile);
return $templateCode;
}
Saubere Links in Extensions erzeugen
Kommentar von Elmar Hinz:
Die Linkfunktionen der tslib_pibase sind nicht garade eine Hilfe. 2/3 davon streichen und die Extension wird 1/3 besser. Wenn Du Dich allein auf die Funktion pi_linkTP_keepPIvars konzentrierst, kannst du damit aber fast alles stemmen. Noch konsequenter wendest du gleich selbst die zugrundeliegende typolink Funktion an.
Das Thema mit dem Fokus auf ein sauberes Caching hier:
Session Variable in Typo3
Session Variablen kann man folgendermaßen spreichern.
$GLOBALS["TSFE"]->fe_user->setKey("ses","$data", "$zustand");
$GLOBALS["TSFE"]->fe_user->storeSessionData();
14.1. Storing user-data or session-data
Userdata => Eingeloggter User. Kein Zugriff mehr wenn ausgeloggt.
Session data => Jeder User. Eingeloggt oder nicht. Daten sind an die "browsing-session" gebunden und nicht an die user-id. Bleibt erhalten bis der Browser geschlossen wird.
Default expire-time of 24 hours.
Funktionen
$GLOBALS["TSFE"]->fe_user->getKey(type, key)
"type" is either "user" or "ses", which defines the data-space, user-data or session-data
"key" is the "name" under which your data is stored. This may be arrays or normal scalars.
Note that the key "recs" is reserved for the built-in "shopping-basket". As is "sys" (for TYPO3 standard modules and code)
Example:
if ($GLOBALS["TSFE"]->loginUser){
$myData = $GLOBALS["TSFE"]->fe_user->getKey("user","myData");
} else {
$myData = $GLOBALS["TSFE"]->fe_user->getKey("ses","myData");
}
This gets the stored data with the key "myData" from the user-data, but if no user is logged in, it's fetched from the session data instead.
$GLOBALS["TSFE"]->fe_user->setKey(type, key, data)
"type" is either "user" or "ses", which defines the data-space, user-data or session-data
"key" is the "name" under which your data is stored.
Note that the key "recs" is reserved for the built-in "shopping-basket". As is "sys" (for TYPO3 standard modules and code)
"data" is the variable, you want to store. This may be arrays or normal scalars.
Example:
$myConfig["name"] = "paul";
$myConfig["address"] = "Main street";
$GLOBALS["TSFE"]->fe_user->setKey("ses","myData", $myConfig);
This stores the array $myConfig under the key "myData" in the session-data. This lasts as long as "paul" is surfing the site!