Contao\Controller::redirect PHP Метод

redirect() публичный статический Метод

Redirect to another page
public static redirect ( string $strLocation, integer $intStatus = 303 )
$strLocation string The target URL
$intStatus integer The HTTP status code (defaults to 303)
    public static function redirect($strLocation, $intStatus = 303)
    {
        if (headers_sent()) {
            exit;
        }
        $strLocation = str_replace('&', '&', $strLocation);
        $strLocation = static::replaceOldBePaths($strLocation);
        // Make the location an absolute URL
        if (!preg_match('@^https?://@i', $strLocation)) {
            $strLocation = \Environment::get('base') . ltrim($strLocation, '/');
        }
        // Ajax request
        if (\Environment::get('isAjaxRequest')) {
            throw new AjaxRedirectResponseException($strLocation);
        }
        throw new RedirectResponseException($strLocation, $intStatus);
    }

Usage Example

Пример #1
0
 public function export(\Contao\DC_Table $dc)
 {
     $database = \Contao\Database::getInstance();
     $stage_id = $database->query("SELECT s.id FROM tl_beachcup_stage AS s WHERE s.start_date >= UNIX_TIMESTAMP() ORDER BY s.start_date ASC LIMIT 1")->fetchAssoc()["id"];
     $data = $database->query("select tl_beachcup_registration.id as ANMELDUNG_ID, tl_beachcup_tournament.name_de AS TURNIER, DATE_FORMAT(from_unixtime(tl_beachcup_registration.tstamp), '%d.%m.%Y') as DATUM_ANMELDUNG,\n                                    p1.surname as NACHNAME_1, p1.name as VORNAME_1, p1.tax_number as STEUER_NR_1, DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL p1.birth_date SECOND), '%d.%m.%Y') as GEB_DATUM_1, p1.birth_place as GEB_ORT_1, p1.gender as GESCHLECHT_1, p1.address as ADRESSE_1, p1.zip_code as PLZ_1, p1.city as ORT_1, p1.country as LAND_1, p1.email as EMAIL_1, p1.phone_number as TEL_1, p1.shirt_size as SHIRT_1, p1.has_shirt as SHIRT_ERHALTEN_1, p1.is_fipav as FIPAV_1, p1level.description_de as SPIELER_LEVEL_1, p1.has_medical_certificate as AERZTL_ZEUGNIS_1, p1.is_confirmed as EIGENERKLAERUNG_1,\n                                    p2.surname as NACHNAME_2, p2.name as VORNAME_2, p2.tax_number as STEUER_NR_2, DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL p2.birth_date SECOND), '%d.%m.%Y') as GEB_DATUM_2, p2.birth_place as GEB_ORT_2, p2.gender as GESCHLECHT_2, p2.address as ADRESSE_2, p2.zip_code as PLZ_2, p2.city as ORT_2, p2.country as LAND_2, p2.email as EMAIL_2, p2.phone_number as TEL_2, p2.shirt_size as SHIRT_2, p2.has_shirt as SHIRT_ERHALTEN_2, p2.is_fipav as FIPAV_2, p2level.description_de as SPIELER_LEVEL_2, p2.has_medical_certificate as AERZTL_ZEUGNIS_2, p2.is_confirmed as EIGENERKLAERUNG_2,\n                                    tl_beachcup_registration_state.code as STATUS_ANMELDUNG\n                                    from tl_beachcup_registration\n                                    join tl_beachcup_team on tl_beachcup_team.id = tl_beachcup_registration.team_id\n                                    join tl_beachcup_player p1 on p1.id =  tl_beachcup_team.player_1\n                                    join tl_beachcup_player_level p1level on p1level.id = p1.player_level\n                                    join tl_beachcup_player p2 on p2.id =  tl_beachcup_team.player_2\n                                    join tl_beachcup_player_level p2level on p2level.id = p2.player_level\n                                    join tl_beachcup_tournament on tl_beachcup_tournament.id = tl_beachcup_registration.tournament_id\n                                    join tl_beachcup_registration_state on tl_beachcup_registration_state.id = tl_beachcup_registration.state_id\n                                    join tl_beachcup_stage on tl_beachcup_stage.id = tl_beachcup_tournament.stage_id\n                                    where tl_beachcup_stage.id = {$stage_id} and tl_beachcup_registration_state.code != 'REJECTED'\n                                    order by tl_beachcup_tournament.date, tl_beachcup_tournament.name_de, tl_beachcup_registration.tstamp;")->fetchAllAssoc();
     if (count($data) > 0) {
         $headers = array();
         foreach ($data[0] as $key => $value) {
             $headers[] = $key;
         }
         $file = fopen("php://memory", "w");
         fputcsv($file, $headers, ";");
         foreach ($data as $record) {
             fputcsv($file, $record, ";");
         }
         fseek($file, 0);
         header('Content-Encoding: iso-8859-1');
         header('Content-Type: application/csv; charset=iso-8859-1');
         header('Content-Disposition: attachement; filename="Anmeldungen.csv";');
         echo "";
         fpassthru($file);
         exit;
     }
     \Contao\Controller::redirect('contao/main.php?do=registration');
 }
All Usage Examples Of Contao\Controller::redirect