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:
}
- 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:
stdWrap.wrap = <font color="red"> | </font>
stdWrap.case = upper
}
- the output will look like this:
JOE SAYS: HELLO WORLD
End of lesson.
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:
"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)
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.
"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.
TYPO3 features a shopping basket for the session-data.
When you submit data from forms (or by querystring) (post/get-method) in the array "recs" it's stored in the session-data under the key recs.
The syntax is like this:
recs[table_name][uid_of_record]
This form-element will change the registered value of record with uid=345 from the "tt_products" table in typo3. Please note, that the record itself is NOT in any way modified, only the "counter" in the session-data indicating the "number of items" from the table is modified.
<input name="recs[tt_products][345]">
NOTE on checkboxes:
When you are creating forms with checkboxes, the value of the checkbox is sent by MSIE/Netscape ONLY if the checkbox is checked! If you want a value sent in case of a disabled checkbox, include a hidden formfield of the same name just before the checkbox!
<INPUT type="hidden" name="recs[tt_content][345]" value="0">
<INPUT type="checkbox" name="recs[tt_content][345]" value="1">