I setup a simple router class that extracts the following
- Controller
- Action
- Parameters
class Router {
private $uri;
private $controller;
private $method;
private $params;
public function __construct($uri) {
$this->uri = $uri;
$this->method = 'index';
$this->params = array();
}
public function map() {
$uri = explode('/', $this->uri);
if (empty($uri[0])) {
$c = new Config('app');
$this->controller = $c->default_controller;
} else {
if (!empty($uri[1]))
$this->method = $uri[1];
// how about the parameters??
}
}
}
That simple $router->map()
can give me the right controller, action and a single parameter from this uri http://domain.com/users/edit/2
That is quite okay, but what if I needed to store more parameters in the url like this :
http://domain.com/controller/action/param/param2/param3
How do I push them to $parms
if I don't know how many parameters will be passed.