切换2个值或其他mothode?

时间:2016-09-19 08:37:02

标签: php switch-statement

我有两个变量:“tl_language”和“filterLanguage”。 现在我使用这段代码:

switch($GLOBALS['TL_LANGUAGE'])
                        {
                            case 'de':
                                if (!$entry->field('beschreibung')->value()){

                                    include ("includes/mediacenter_content_de.php");
                                }else{
                                    include ("includes/mediacenter_content_en.php");
                                }
                                break;
                            case 'en':
                                if (!$entry->field('beschreibung')->value()){

                                    include ("includes/mediacenter_content_en.php");
                                }else{
                                    include ("includes/mediacenter_content_de.php");
                                }
                                break;
                            case 'fr':
                                if (!$entry->field('beschreibung')->value()){

                                    include ("includes/mediacenter_content_fr.php");
                                }else{
                                    include ("includes/mediacenter_content_en.php");
                                }
                                break;
                            case 'nl':
                                if (!$entry->field('beschreibung')->value()){

                                    include ("includes/mediacenter_content_nl.php");
                                }else{
                                    include ("includes/mediacenter_content_en.php");
                                }
                                break;
                            default:
                                echo $entry->field('beschreibung_englisch')->value();
                                break;
                        }

                        ?>

现在我想添加一个过滤器,用户可以单独过滤语言。 例如。如果tl_language是“de”show germ一个内容,或者filterLanguage是“de”显示德语内容。

现在,我正在尝试这样的事情:

    if($GLOBALS['TL_LANGUAGE'] =="de" or $cc_language == "de"){
    if (!$entry->field('beschreibung')->value()){

        include ("includes/mediacenter_content_de.php");
    }else{
        include ("includes/mediacenter_content_en.php");
    }
}
if($GLOBALS['TL_LANGUAGE'] =="en" or $cc_language == "en"){
     if (!$entry->field('beschreibung')->value()){

        include ("includes/mediacenter_content_en.php");
    }else{
        include ("includes/mediacenter_content_de.php");
    }
}

但它显示了双重内容。

1 个答案:

答案 0 :(得分:1)

我建议使用第三个变量。我认为$cc_language具有更高的优先级。使用您的第一个代码。

$lang = ( isset($cc_language)  && !empty($cc_language) ) ? $cc_language : $GLOBALS['TL_LANGUAGE'];

switch( $lang ) {