Reputation: 3163
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?
Upvotes: 0
Views: 101
Reputation: 15097
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;
}
}
Upvotes: 2
Reputation: 26441
Can do,
$m = isset($_GET['m']) ? $_GET['m'] : "";
$v = isset($_GET['v']) ? $_GET['v'] : "";
Router::Get($m, $v);
Upvotes: 7