sitegeist / base-url

Get absolute URL from TYPO3 site configurations and prepend it to relative URLs.
GNU General Public License v2.0
1 stars 1 forks source link
typo3 typo3-extension uri url

Base URL for TYPO3 commands and tasks

In in scripts where no FE or BE context is available and you want to build URLs its a good idea to get the absolute URL from a site configuration. This extension provides a helper class to get there.

Where to use

Features

Getting Started

use the static functions from BaseUrl helper Class

\Sitegeist\BaseUrl\Helper\BaseUrl::get(); // https://example.com/
\Sitegeist\BaseUrl\Helper\BaseUrl::prepend('home.html'); // https://example.com/home.html

use the viewhelpers in your fluid templates e. g. for mails

<baseurl:get /> <!-- https://example.com/ -->
<baseurl:prepend>home.html</baseurl:prepend> <!-- https://example.com/home.html -->

Multiple site configuration setups

if your system has more than one site configuration, you can specify which site configuration should be used by:

Getting further

Disable $asString return type to get an TYPO3\CMS\Core\Http\Uri object. Now you can get or change specific parts of the url.

BaseUrl::get(null, null, true, false);

BaseUrl::prepend('home.html', null, null, true, false);
/*
TYPO3\CMS\Core\Http\Uri prototype object
   scheme => protected "https" (5 chars)
   supportedSchemes => protected array(2 items)
      http => 80 (integer)
      https => 443 (integer)
   authority => protected "" (0 chars)
   userInfo => protected "" (0 chars)
   host => protected "example.com" (11 chars)
   port => protected NULL
   path => protected "home.html" (9 chars)
   query => protected "" (0 chars)
   fragment => protected NULL
*/