Contao\Input::setGet PHP Method

setGet() public static method

Set a $_GET variable
public static setGet ( string $strKey, mixed $varValue, boolean $blnAddUnused = false )
$strKey string The variable name
$varValue mixed The variable value
$blnAddUnused boolean If true, the value usage will be checked
    public static function setGet($strKey, $varValue, $blnAddUnused = false)
    {
        // Convert special characters (see #7829)
        $strKey = str_replace(array(' ', '.', '['), '_', $strKey);
        $strKey = static::cleanKey($strKey);
        unset(static::$arrCache['getEncoded'][$strKey]);
        unset(static::$arrCache['getDecoded'][$strKey]);
        if ($varValue === null) {
            unset($_GET[$strKey]);
        } else {
            $_GET[$strKey] = $varValue;
            if ($blnAddUnused) {
                static::setUnusedGet($strKey, $varValue);
                // see #4277
            }
        }
    }

Usage Example

 /**
  * @param $intId
  * @param $blnVisible
  * @param DataContainer|null $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     // Check the field access
     if (!$this->User->hasAccess('tl_api_client::disable', 'alexf')) {
         throw new AccessDeniedException('Not enough permissions to activate/deactivate member ID ' . $intId . '.');
     }
     $objVersions = new Versions('tl_api_client', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_api_client']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_api_client']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     $time = time();
     // Update the database
     $this->Database->prepare("UPDATE tl_api_client SET tstamp={$time}, disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_api_client.id=' . $intId . '" has been created' . $this->getParentEntries('tl_api_client', $intId), __METHOD__, TL_GENERAL);
 }
All Usage Examples Of Contao\Input::setGet