core-bundle/src/Resources/contao/library/Contao/Controller.php
public static function generateFrontendUrl(array $arrRow, $strParams=null, $strForceLang=null, $blnFixDomain=false)
	{
		@trigger_error('Using Controller::generateFrontendUrl() has been deprecated and will no longer work in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.', E_USER_DEPRECATED);

		if (!isset($arrRow['rootId']))
		{
			$row = PageModel::findWithDetails($arrRow['id']);

			$arrRow['rootId'] = $row->rootId;

			foreach (array('domain', 'rootLanguage', 'rootUseSSL') as $key)
			{
				if (!isset($arrRow[$key]))
				{
					$arrRow[$key] = $row->$key;
				}
			}
		}

		$arrParams = array();

		// Set the language
		if ($strForceLang != '')
		{
			$arrParams['_locale'] = $strForceLang;
		}
		elseif (isset($arrRow['rootLanguage']))
		{
			$arrParams['_locale'] = $arrRow['rootLanguage'];
		}
		elseif (isset($arrRow['language']) && $arrRow['type'] == 'root')
		{
			$arrParams['_locale'] = $arrRow['language'];
		}
		elseif (TL_MODE == 'FE')
		{
			/** @var PageModel $objPage */
			global $objPage;

			$arrParams['_locale'] = $objPage->rootLanguage;
		}

		// Add the domain if it differs from the current one (see #3765 and #6927)
		if ($blnFixDomain)
		{
			$arrParams['_domain'] = $arrRow['domain'];
			$arrParams['_ssl'] = (bool) $arrRow['rootUseSSL'];
		}

		$objUrlGenerator = System::getContainer()->get('contao.routing.url_generator');
		$strUrl = $objUrlGenerator->generate(($arrRow['alias'] ?: $arrRow['id']) . $strParams, $arrParams);

		// Remove path from absolute URLs
		if (0 === strncmp($strUrl, '/', 1))
		{
			$strUrl = substr($strUrl, \strlen(Environment::get('path')) + 1);
		}

		// Decode sprintf placeholders
		if (strpos($strParams, '%') !== false)
		{
			$arrMatches = array();
			preg_match_all('/%([sducoxXbgGeEfF])/', $strParams, $arrMatches);

			foreach (array_unique($arrMatches[1]) as $v)
			{
				$strUrl = str_replace('%25' . $v, '%' . $v, $strUrl);
			}
		}

		// HOOK: add custom logic
		if (isset($GLOBALS['TL_HOOKS']['generateFrontendUrl']) && \is_array($GLOBALS['TL_HOOKS']['generateFrontendUrl']))
		{
			foreach ($GLOBALS['TL_HOOKS']['generateFrontendUrl'] as $callback)
			{
				$strUrl = static::importStatic($callback[0])->{$callback[1]}($arrRow, $strParams, $strUrl);
			}
		}

		return $strUrl;
	}
public static function generateFrontendUrl(array $arrRow, $strParams=null, $strForceLang=null, $blnFixDomain=false)
	{
		@trigger_error('Using Controller::generateFrontendUrl() has been deprecated and will no longer work in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.', E_USER_DEPRECATED);

		if (!isset($arrRow['rootId']))
		{
			$row = PageModel::findWithDetails($arrRow['id']);

			$arrRow['rootId'] = $row->rootId;

			foreach (array('domain', 'rootLanguage', 'rootUseSSL') as $key)
			{
				if (!isset($arrRow[$key]))
				{
					$arrRow[$key] = $row->$key;
				}
			}
		}

		$arrParams = array();

		// Set the language
		if ($strForceLang != '')
		{
			$arrParams['_locale'] = $strForceLang;
		}
		elseif (isset($arrRow['rootLanguage']))
		{
			$arrParams['_locale'] = $arrRow['rootLanguage'];
		}
		elseif (isset($arrRow['language']) && $arrRow['type'] == 'root')
		{
			$arrParams['_locale'] = $arrRow['language'];
		}
		elseif (TL_MODE == 'FE')
		{
			/** @var PageModel $objPage */
			global $objPage;

			$arrParams['_locale'] = $objPage->rootLanguage;
		}

		// Add the domain if it differs from the current one (see #3765 and #6927)
		if ($blnFixDomain)
		{
			$arrParams['_domain'] = $arrRow['domain'];
			$arrParams['_ssl'] = (bool) $arrRow['rootUseSSL'];
		}

		$objUrlGenerator = System::getContainer()->get('contao.routing.url_generator');
		$strUrl = $objUrlGenerator->generate(($arrRow['alias'] ?: $arrRow['id']) . $strParams, $arrParams);

		// Remove path from absolute URLs
		if (0 === strncmp($strUrl, '/', 1))
		{
			$strUrl = substr($strUrl, \strlen(Environment::get('path')) + 1);
		}

		// Decode sprintf placeholders
		if (strpos($strParams, '%') !== false)
		{
			$arrMatches = array();
			preg_match_all('/%([sducoxXbgGeEfF])/', $strParams, $arrMatches);

			foreach (array_unique($arrMatches[1]) as $v)
			{
				$strUrl = str_replace('%25' . $v, '%' . $v, $strUrl);
			}
		}

		// HOOK: add custom logic
		if (isset($GLOBALS['TL_HOOKS']['generateFrontendUrl']) && \is_array($GLOBALS['TL_HOOKS']['generateFrontendUrl']))
		{
			foreach ($GLOBALS['TL_HOOKS']['generateFrontendUrl'] as $callback)
			{
				$strUrl = static::importStatic($callback[0])->{$callback[1]}($arrRow, $strParams, $strUrl);
			}
		}

		return $strUrl;
	}
public static function generateFrontendUrl ( array $ arrRow , $ strParams = null , $ strForceLang = null , $ blnFixDomain = false ) { @ trigger_error ( 'Using Controller::generateFrontendUrl() has been deprecated and will no longer work in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.' , E_USER_DEPRECATED ) ; if ( ! isset ( $ arrRow [ 'rootId' ] ) ) { $ row = PageModel :: findWithDetails ( $ arrRow [ 'id' ] ) ; $ arrRow [ 'rootId' ] = $ row -> rootId ; foreach ( array ( 'domain' , 'rootLanguage' , 'rootUseSSL' ) as $ key ) { if ( ! isset ( $ arrRow [ $ key ] ) ) { $ arrRow [ $ key ] = $ row -> $ key ; } } } $ arrParams = array ( ) ; // Set the language if ( $ strForceLang != '' ) { $ arrParams [ '_locale' ] = $ strForceLang ; } elseif ( isset ( $ arrRow [ 'rootLanguage' ] ) ) { $ arrParams [ '_locale' ] = $ arrRow [ 'rootLanguage' ] ; } elseif ( isset ( $ arrRow [ 'language' ] ) && $ arrRow [ 'type' ] == 'root' ) { $ arrParams [ '_locale' ] = $ arrRow [ 'language' ] ; } elseif ( TL_MODE == 'FE' ) { /** @var PageModel $objPage */ global $ objPage ; $ arrParams [ '_locale' ] = $ objPage -> rootLanguage ; } // Add the domain if it differs from the current one (see #3765 and #6927) if ( $ blnFixDomain ) { $ arrParams [ '_domain' ] = $ arrRow [ 'domain' ] ; $ arrParams [ '_ssl' ] = ( bool ) $ arrRow [ 'rootUseSSL' ] ; } $ objUrlGenerator = System :: getContainer ( ) -> get ( 'contao.routing.url_generator' ) ; $ strUrl = $ objUrlGenerator -> generate ( ( $ arrRow [ 'alias' ] ? : $ arrRow [ 'id' ] ) . $ strParams , $ arrParams ) ; // Remove path from absolute URLs if ( 0 === strncmp ( $ strUrl , '/' , 1 ) ) { $ strUrl = substr ( $ strUrl , \ strlen ( Environment :: get ( 'path' ) ) + 1 ) ; } // Decode sprintf placeholders if ( strpos ( $ strParams , '%' ) !== false ) { $ arrMatches = array ( ) ; preg_match_all ( '/%([sducoxXbgGeEfF])/' , $ strParams , $ arrMatches ) ; foreach ( array_unique ( $ arrMatches [ 1 ] ) as $ v ) { $ strUrl = str_replace ( '%25' . $ v , '%' . $ v , $ strUrl ) ; } } // HOOK: add custom logic if ( isset ( $ GLOBALS [ 'TL_HOOKS' ] [ 'generateFrontendUrl' ] ) && \ is_array ( $ GLOBALS [ 'TL_HOOKS' ] [ 'generateFrontendUrl' ] ) ) { foreach ( $ GLOBALS [ 'TL_HOOKS' ] [ 'generateFrontendUrl' ] as $ callback ) { $ strUrl = static :: importStatic ( $ callback [ 0 ] ) -> { $ callback [ 1 ] } ( $ arrRow , $ strParams , $ strUrl ) ; } } return $ strUrl ; }
Generate a front end URL

@param array   $arrRow       An array of page parameters
@param string  $strParams    An optional string of URL parameters
@param string  $strForceLang Force a certain language
@param boolean $blnFixDomain Check the domain of the target page and append it if necessary

@return string An URL that can be used in the front end

@deprecated Deprecated since Contao 4.2, to be removed in Contao 5.0.
Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.
Generate a front end URL