How to know if a current page have parameter ?

thread: 8 messages  |  last: a year ago  |  started: thursday, april 15, 2010, 4:23 am pdt


#1  |  Mattia Bagiella (Switzerland) Switzerland
Thursday, April 15, 2010, 4:23 AM PDT

Hello all,

I explain my problem : I have a website with 4 languages FR-DE-EN-IT and I want that when I click the language the current page need to be translated.

It's work when the page dont have any parameter.

with the page like this :
http://localhost:8888/contographie/index.php --> WORK
http://localhost:8888/contographie/index.php?lang=fr
But when i have this when I want to change to english :
http://localhost:8888/contographie/index.php?lang=fr?lang=en -> is not working :(

here the code


<?php

public function lnkLang_clic($strFormId$strControlId$strParameter){
            
$currentPage $_SERVER["REQUEST_URI"];
            
QApplication::Redirect($currentPage.'?lang='.$strParameter);
    }

?>


The code in the prepend.inc

<?php
/////////////////////////////
        // Start Session Handler (if required)
        /////////////////////////////
        
session_start();

        
//////////////////////////////////////////////
        // Setup Internationalization and Localization (if applicable)
        // Note, this is where you would implement code to do Language Setting discovery, as well, for example:
        // * Checking against $_GET['language_code']
        // * checking against session (example provided below)
        // * Checking the URL
        // * etc.
        // TODO: options to do this are left to the developer
        //////////////////////////////////////////////
        
if(isset($_GET['lang'])){
            
$_SESSION['language_code'] = $_GET['lang'];
        }
        
        if (isset(
$_SESSION)) {
            if (
array_key_exists('country_code'$_SESSION))
                
QApplication::$CountryCode $_SESSION['country_code'];
            if (
array_key_exists('language_code'$_SESSION))
                
QApplication::$LanguageCode $_SESSION['language_code'];
        }
        else{
            
QApplication::$LanguageCode 'fr';
            
$_SESSION['language_code'] = QApplication::$LanguageCode;
        }
        
        
$langFile __DOCROOT__ '/lang/lang_' QApplication::$LanguageCode '.php';
        if(
file_exists($langFile)){
            require_once(
$langFile);
        }
        else{
            require_once(
__DOCROOT__ '/lang/lang_fr.php');
        }
?>

I hope that you get my problem and can help me, I would be very thankfull :P

What I would like it's that if the page it's like this :
http://localhost:8888/contographie/index.php?lang=fr
if I click english I would like that “?lang=fr” is replaced by “?lang=en” and no add in the end like before.
OR
Never have this parameter visible “?lang=...” but I don't know how to manage the change of language without it

And if the page have parameter the “?lang=fr” is modified like this “&lang=fr” :D

Sorry for my bad english hope that I'm quite understandable with my problem

#2  |  Mattia Bagiella (Switzerland) Switzerland
Thursday, April 15, 2010, 5:30 AM PDT

I make something and now it's working but it's quite ugly here the new code


<?php

public function lnkLang_clic($strFormId$strControlId$strParameter){
            
$currentPage $_SERVER["REQUEST_URI"];
            
$lang '?lang=';
            
$tab parse_url($currentPage);
            if(isset(
$_GET['lang']) OR isset($tab['query'])) $lang='&lang=';
            
QApplication::Redirect($currentPage.$lang.$strParameter);
    }

?>

If you have a better solution please tell me :D

#3  |  Zbyszek Czarnecki (Warsaw, PL) Poland
Thursday, April 15, 2010, 5:43 AM PDT

I would use QApplication::$ScriptName instead of QApplication::$RequestUri and add query string like in your first example.

ScriptName doesn't containt query string.

But this way you overwrite your query string so if you plan to send other parameters in your query string it won't work.

If you need to modify just lang parameter you could use http://php.net/manual/en/class.httpquerystring.php

#4  |  Mattia Bagiella (Switzerland) Switzerland
Thursday, April 15, 2010, 12:52 PM PDT

Thank you but how I can use this HttpQuery ? Didn't exist with qcodo ?
Your method work only if no other query on the page


<?php    

public function lnkLang_clic($strFormId$strControlId$strParameter){
            
$query = new HttpQueryString(false);
            
$query->set('lang='.$strParameter);

//            $currentPage = $_SERVER["REQUEST_URI"];
//            $lang = '?lang=';
//            $tab = parse_url($currentPage);
//            if(isset($_GET['lang']) OR isset($tab['query'])) $lang='&lang=';
//            QApplication::Redirect($currentPage.$lang.$strParameter);
    
}

?>

Dont work :(

I edited my code like this


<?php

public function lnkLang_clic($strFormId$strControlId$strParameter){
            
$currentPage $_SERVER["REQUEST_URI"];
            
$lang '?lang=';
            if(
$_SERVER['QUERY_STRING']) $lang='&lang=';
            
QApplication::Redirect($currentPage.$lang.$strParameter);
    }

?>

But if I just want to update the lang ? How I could manage with HttpQueryString because like this if i click a hundred time on the language EN i will have

?lang=en&lang=en&lang=en&lang=en ...

#5  |  VexedPanda (Calgary, AB) Canada
Thursday, April 15, 2010, 1:32 PM PDT

Why not set $_GET['lang'] and then use QApplication::GenerateQueryString() ?

#6  |  Mattia Bagiella (Switzerland) Switzerland
Thursday, April 15, 2010, 1:53 PM PDT

How you manage to do it ?

I really don't understand :S

#7  |  VexedPanda (Calgary, AB) Canada
Friday, April 16, 2010, 8:32 AM PDT
<?php
public function lnkLang_clic($strFormId$strControlId$strParameter){
            
$_GET['lang'] = $strParameter;
            
QApplication::Redirect(QApplication::$ScriptName.QApplication::GenerateQueryString());
    }
?>
.bc
#8  |  Mattia Bagiella (Switzerland) Switzerland
Friday, April 16, 2010, 11:38 AM PDT

Super thank you very much it's very much better than before now

Thank you you you you

:D



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.