Apr 12, 2012

When not to use typoLink

For a long time I tell everybody to use typoLink to create links inside TYPO3.

A “go”:

$url = $this->cObj->typoLink_URL(array(
    'parameter' => $GLOBALS['TSFE']->id

A “no go”:

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

But there is one case when you absolutely must not use typoLink to create the URL. It is when the URL points to the eID script. Why? Because there is no resolving of the speaking URL inside eID anyway. So it is a complete waste of time and memory to have something like /path/to/my/news/page/news/how-i-bought-a-car.html?eID=tx_myext_eid.

Just do it like this:

$url = t3lib_div::locationHeaderUrl('index.php?eID=tx_myext_eid').

That's the right way.