Core Documentation

Here you will find the new official reference manuals. These documents are related to the core of TYPO3 and address the built in functionality of TYPO3. They are designed to provide you with in-depth information.

Old Core Documentation


Chapter 14. Casestory:

This is a casestory of how to use include-scripts.

In this situation we would like to use some libraries of our very own, not part of TYPO3. Therefore we use the feature of including a library at the very beginning of the page-parsing.

First we put this TypoScript line in the  "Setup"-field of the template:

config.includeLibrary = fileadmin/scripts/include.inc

The file include.inc is now included (in typo3/sysext/cms/tslib/pagegen.php). In this case it looks like this:

file:   fileadmin/scripts/include.inc

<?
...
include("/fileadmin/scripts/hello_world.inc");
include("/fileadmin/scripts/other_library.inc");
...
?>

As you can see, this file includes our library "hello_world" and some other libraries too!

The file hello_world.inc looks like this:

file:   fileadmin/scripts/hello_world.inc

<?
class hello_world {
function theMessage (){
return "Hello World";
}
}
?>

So far nothing has happend, except our libraries are included, ready for use.

Now we need to use the outcome of the hello_world class somewhere on a page. So in the TypoScript code we setup a content-object that includes the third script:

page.100 = PHP_SCRIPT
page.100.file = fileadmin/scripts/surprise.inc

surprise.inc looks like this:

file:   fileadmin/scripts/surprise.inc

<?
$hello_world_object = new hello_world;// New instance is created
$contentBefore = $this->cObjGetSingle($conf["cObj"],$conf["cObj."]);
$content = $contentBefore.$hello_world_object->theMessage();
$content = $this->stdWrap($content,$conf["stdWrap."]);
?>

Line 1: The PHP-object $hello_world_object is created.

Line 2: This fetches the content of a cObject, "cObj", we defined

Line 3: The result of line 2 is concatenated with the result of the "theMessage"-function of the $hello_world_object object

Line 4: Finally the content is stdWrap'ed with the properties of ".stdWrap" of the $conf-array.

The output:

With this configuration -

page.100 = PHP_SCRIPT
page.100.file = fileadmin/scripts/surprise.inc

- the output will look like this:

Hello World

With this configuration -

page.100 = PHP_SCRIPT
page.100 {
file = fileadmin/scripts/surprise.inc
cObj = TEXT
cObj.value = Joe says:&nbsp;
}

- the output will look like this:

Joe says: Hello World

 With this configuration -

page.100 = PHP_SCRIPT
page.100 {
file = fileadmin/scripts/surprise.inc
cObj = TEXT
cObj.value = Joe says:&nbsp;
stdWrap.wrap = <font color="red"> | </font>
 stdWrap.case = upper
}

- the output will look like this:

JOE SAYS: HELLO WORLD

End of lesson.

14.1. Storing user-data or session-data

Doing so is quite simple with TYPO3.

Userdata is data, that follows login users. As soon as a login user is logged out, these data are no more accessible and cannot be altered.

Session data is data, that follows the user currently browsing the site. This user may be a login-user, but his session-data is bound to the "browsing-session" and not to the user-id of his. This means, that the very same person will carry this data still, even if he logs out. As soon as he closes his browser, his data will be gone though.

Also you should know, that session-data has a default expire-time of 24 hours.

Retrieving and storing user-/session-data is done by these functions:

$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!