MVC Router in php
class Router {
public static function route(Request $request) {
$controllerName = $request->getController() . 'Controller';
$methodName = $request->getMethod();
$args = $request->getArgs();
if(is_readable(CONTROLLERS . $controllerName . '.php')) {
$controller = new $controllerName;
$method = (is_callable(array($controller, $methodName))) ? $methodName : 'main';
if(!empty($args)) {
call_user_func_array(array($controller, $method), $args);
} else {
call_user_func(array($controller, $method));
}
return;
}
throw new Exception('wrong_route');
}
}
Written by Krzysztof
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#