문제

I just wrote this and was thinking there must be an easier/more clean way to do this as it looks terrible doing it this way:

if(isset($_GET['m']) && isset($_GET['v'])) {
    Router::Get($_GET['m'], $_GET['v']);
} elseif(isset($_GET['m'])) {
    Router::Get($_GET['m'], "");
} else {
    Router::Get("", "");
}

I'm looking for a cleaner way, like:

Router::Get(is('m'), is('v'));

Any suggestions to shorten/clean this kind of if-statements?

도움이 되었습니까?

해결책 2

You can encapsulate the logic:

Router::$query = $_GET;
Router::Get('m', Router::Get('v'))

class Router {
    static public $query;
    static function Get($name, $default = '') {
        return isset(self::$query[$name]) ? self::$query[$name] : $default;
    }
}

다른 팁

Can do,

$m = isset($_GET['m']) ? $_GET['m'] : "";
$v = isset($_GET['v']) ? $_GET['v'] : "";
Router::Get($m, $v);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top