Contao\Input::get PHP Method

get() public static method

Return a $_GET variable
public static get ( string $strKey, boolean $blnDecodeEntities = false, boolean $blnKeepUnused = false ) : mixed
$strKey string The variable name
$blnDecodeEntities boolean If true, all entities will be decoded
$blnKeepUnused boolean If true, the parameter will not be marked as used (see #4277)
return mixed The cleaned variable value
    public static function get($strKey, $blnDecodeEntities = false, $blnKeepUnused = false)
    {
        if (!isset($_GET[$strKey])) {
            return null;
        }
        $strCacheKey = $blnDecodeEntities ? 'getDecoded' : 'getEncoded';
        if (!isset(static::$arrCache[$strCacheKey][$strKey])) {
            $varValue = $_GET[$strKey];
            $varValue = static::decodeEntities($varValue);
            $varValue = static::xssClean($varValue, true);
            $varValue = static::stripTags($varValue);
            if (!$blnDecodeEntities) {
                $varValue = static::encodeSpecialChars($varValue);
            }
            $varValue = static::encodeInsertTags($varValue);
            static::$arrCache[$strCacheKey][$strKey] = $varValue;
        }
        // Mark the parameter as used (see #4277)
        if (!$blnKeepUnused) {
            unset(static::$arrUnusedGet[$strKey]);
        }
        return static::$arrCache[$strCacheKey][$strKey];
    }

Usage Example

 /**
  * Run the controller and parse the template
  *
  * @return Response
  */
 public function run()
 {
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_preview');
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->site = \Input::get('site', true);
     $objTemplate->switchHref = \System::getContainer()->get('router')->generate('contao_backend_switch');
     if (\Input::get('url')) {
         $objTemplate->url = \Environment::get('base') . \Input::get('url');
     } elseif (\Input::get('page')) {
         $objTemplate->url = $this->redirectToFrontendPage(\Input::get('page'), \Input::get('article'), true);
     } else {
         $objTemplate->url = \System::getContainer()->get('router')->generate('contao_root', [], UrlGeneratorInterface::ABSOLUTE_URL);
     }
     // Switch to a particular member (see #6546)
     if (\Input::get('user') && $this->User->isAdmin) {
         $objUser = \MemberModel::findByUsername(\Input::get('user'));
         if ($objUser !== null) {
             $strHash = $this->getSessionHash('FE_USER_AUTH');
             // Remove old sessions
             $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute(time() - \Config::get('sessionTimeout'), $strHash);
             // Insert the new session
             $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute($objUser->id, time(), 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash);
             // Set the cookie
             $this->setCookie('FE_USER_AUTH', $strHash, time() + \Config::get('sessionTimeout'), null, null, false, true);
             $objTemplate->user = \Input::post('user');
         }
     }
     return $objTemplate->getResponse();
 }
All Usage Examples Of Contao\Input::get