Contao\Controller::generateFrontendUrl PHP 메소드

generateFrontendUrl() 공개 정적인 메소드

Generate a front end URL
사용 중단: Deprecated since Contao 4.2, to be removed in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.
public static generateFrontendUrl ( array $arrRow, string $strParams = null, string $strForceLang = null, boolean $blnFixDomain = false ) : string
$arrRow array An array of page parameters
$strParams string An optional string of URL parameters
$strForceLang string Force a certain language
$blnFixDomain boolean Check the domain of the target page and append it if necessary
리턴 string An URL that can be used in the front end
    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 = [];
        // 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 === strpos($strUrl, '/')) {
            $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;
    }

Usage Example

예제 #1
0
 /**
  * Generate a front end URL
  *
  * @param string $strParams    An optional string of URL parameters
  * @param string $strForceLang Force a certain language
  *
  * @return string An URL that can be used in the front end
  */
 public function getFrontendUrl($strParams = null, $strForceLang = null)
 {
     return \Controller::generateFrontendUrl($this->row(), $strParams, $strForceLang);
 }
All Usage Examples Of Contao\Controller::generateFrontendUrl