By Robert Lemke
When it comes to links in frontend plugins, some pitfalls arise which circumvent other vital mechanisms like the “L” flag for multilingual websites and thus creates conflicts while using your extension within the TYPO3 framework. This article demonstrates how to use TYPO3's various API functions for link generation.
This tutorial is intended for all kinds of TYPO3 extension programmers who create frontend plugins or frontend related code using the TYPO3 framework.
You should be able to create a basic frontend plugin by using the Extension Kickstarter and have a basic knowledge of how TypoScript works.
Your first question probably is, why you should use special functions to create links in TYPO3 at all? Let's have a look at a manually created internal link:
$content = '<a href="index.php?id='.$GLOBALS['TSFE']->id.
'&doTheMagic=1">Do it!</a>';
That piece of code will work like you expect it: It will jump to the current page and pass the parameter doTheMagic to your script. Great.
Almost.
Just imagine, you are running a multi-lingual website. The information about the currently selected language will usually be passed from page to page by adding the parameter &L=x to the URL where x is an integer value corresponding with the uid of the sys_language record.
Now, if the visitor of your website clicks the magic button in your frontend plugin, the L flag won't be transmitted and the next page will be displayed with the default language, ignoring whatever language has been selected before.
Okay, let's take that into account:
$content = '<a href="index.php?id='.$GLOBALS['TSFE']->id.
'&L=' . intval (t3lib_div::_GP('L')).
'&doTheMagic=1">Do it!</a>';
Now the L parameter will be added to your URL and the next page will be displayed in the correct language. Great. Almost, because what happens if there are parameters you don't know of?