douyan8413 2015-02-01 20:21
浏览 36
已采纳

Php访问类上的静态方法

First all i'm new on OOP. Sorry if this is a noob question.

I'm building a multilanguage web site. I'm fetching database values with languga iso's. For eg: index.php?lang=en if language value is set with $_GET parameter, mysql brings only en values in database. The problem is with my LanguageController.

// LanguageController Class
class LanguageController {
    public $lang = "en";
    public function __construct() {
        return true;    
    }
    public static function detectLang() {
        $lang = 'en';
        ob_start();
        session_start();
        if(isset($_GET["lang"])) {
            $lang= $_GET["lang"];
            $_SESSION["lang"] = $lang;
            setcookie("lang", $lang, time() + (3600 * 24 * 30));
        }
        else {
            $lang = 'en';
            $_SESSION["lang"] = $lang;
            setcookie("lang", $lang, time() + (3600 * 24 * 30));
            return true;
        }
    }
}

I want to pass default $lang parameter for eg 'en'. If client change language to 'fr', i must start a session. And mysql brings 'fr' language values. How can i pass my $lang parameter on my detectLang() method.

I tried var_dump(LanguageController::detectLang()) It's coming NULL.

Any help greatly appricated.

  • 写回答

2条回答 默认 最新

  • doujing5726 2015-02-01 20:26
    关注

    When there's no return statement in a function - returned value is NULL. Obviously your detectLang function works and the isset($_GET["lang"]) condition is true, in this case the returned value is NULL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,