Contao\Controller::addToUrl PHP Method

addToUrl() public static method

Add a request string to the current URL
public static addToUrl ( string $strRequest, boolean $blnAddRef = true, array $arrUnset = [] ) : string
$strRequest string The string to be added
$blnAddRef boolean Add the referer ID
$arrUnset array An optional array of keys to unset
return string The new URL
    public static function addToUrl($strRequest, $blnAddRef = true, $arrUnset = array())
    {
        /** @var Query $query */
        $query = new Query(\Environment::get('queryString'));
        // Remove the request token and referer ID
        $query = $query->without(array_merge(array('rt', 'ref'), $arrUnset));
        // Merge the request string to be added
        $query = $query->merge(new Query(str_replace('&', '&', $strRequest)));
        // Add the referer ID
        if (isset($_GET['ref']) || $strRequest != '' && $blnAddRef) {
            $query = $query->merge('ref=' . TL_REFERER_ID);
        }
        return TL_SCRIPT . $query->getUriComponent();
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Generate the navigation menu and return it as array
  *
  * @param boolean $blnShowAll
  *
  * @return array
  */
 public function navigation($blnShowAll = false)
 {
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $arrModules = array();
     $session = $objSessionBag->all();
     // Toggle nodes
     if (\Input::get('mtg')) {
         $session['backend_modules'][\Input::get('mtg')] = isset($session['backend_modules'][\Input::get('mtg')]) && $session['backend_modules'][\Input::get('mtg')] == 0 ? 1 : 0;
         $objSessionBag->replace($session);
         \Controller::redirect(preg_replace('/(&(amp;)?|\\?)mtg=[^& ]*/i', '', \Environment::get('request')));
     }
     foreach ($GLOBALS['BE_MOD'] as $strGroupName => $arrGroupModules) {
         if (!empty($arrGroupModules) && ($strGroupName == 'system' || $this->hasAccess(array_keys($arrGroupModules), 'modules'))) {
             $arrModules[$strGroupName]['icon'] = 'modMinus.gif';
             $arrModules[$strGroupName]['title'] = specialchars($GLOBALS['TL_LANG']['MSC']['collapseNode']);
             $arrModules[$strGroupName]['label'] = ($label = is_array($GLOBALS['TL_LANG']['MOD'][$strGroupName]) ? $GLOBALS['TL_LANG']['MOD'][$strGroupName][0] : $GLOBALS['TL_LANG']['MOD'][$strGroupName]) != false ? $label : $strGroupName;
             $arrModules[$strGroupName]['href'] = \Controller::addToUrl('mtg=' . $strGroupName);
             // Do not show the modules if the group is closed
             if (!$blnShowAll && isset($session['backend_modules'][$strGroupName]) && $session['backend_modules'][$strGroupName] < 1) {
                 $arrModules[$strGroupName]['modules'] = false;
                 $arrModules[$strGroupName]['icon'] = 'modPlus.gif';
                 $arrModules[$strGroupName]['title'] = specialchars($GLOBALS['TL_LANG']['MSC']['expandNode']);
             } else {
                 foreach ($arrGroupModules as $strModuleName => $arrModuleConfig) {
                     // Check access
                     if ($strModuleName == 'undo' || $this->hasAccess($strModuleName, 'modules')) {
                         $arrModules[$strGroupName]['modules'][$strModuleName] = $arrModuleConfig;
                         $arrModules[$strGroupName]['modules'][$strModuleName]['title'] = specialchars($GLOBALS['TL_LANG']['MOD'][$strModuleName][1]);
                         $arrModules[$strGroupName]['modules'][$strModuleName]['label'] = ($label = is_array($GLOBALS['TL_LANG']['MOD'][$strModuleName]) ? $GLOBALS['TL_LANG']['MOD'][$strModuleName][0] : $GLOBALS['TL_LANG']['MOD'][$strModuleName]) != false ? $label : $strModuleName;
                         $arrModules[$strGroupName]['modules'][$strModuleName]['icon'] = !empty($arrModuleConfig['icon']) ? sprintf(' style="background-image:url(\'%s%s\')"', TL_ASSETS_URL, $arrModuleConfig['icon']) : '';
                         $arrModules[$strGroupName]['modules'][$strModuleName]['class'] = 'navigation ' . $strModuleName;
                         $arrModules[$strGroupName]['modules'][$strModuleName]['href'] = TL_SCRIPT . '?do=' . $strModuleName . '&amp;ref=' . TL_REFERER_ID;
                         // Mark the active module and its group
                         if (\Input::get('do') == $strModuleName) {
                             $arrModules[$strGroupName]['class'] = ' trail';
                             $arrModules[$strGroupName]['modules'][$strModuleName]['class'] .= ' active';
                         }
                     }
                 }
             }
         }
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getUserNavigation']) && is_array($GLOBALS['TL_HOOKS']['getUserNavigation'])) {
         foreach ($GLOBALS['TL_HOOKS']['getUserNavigation'] as $callback) {
             $this->import($callback[0]);
             $arrModules = $this->{$callback[0]}->{$callback[1]}($arrModules, $blnShowAll);
         }
     }
     return $arrModules;
 }
All Usage Examples Of Contao\Controller::addToUrl