Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Router {
- private $uri;
- private $controller;
- private $action;
- private $params;
- public function __construct($uri) {
- $this->uri = $uri;
- $this->action = '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 {
- $this->controller = array_shift($uri);
- if (!empty($uri[1]))
- $this->action = array_shift($uri);
- if(!empty($uri[2]))
- $this->params = $uri;
- }
- }
- public function getController() {
- return $this->controller;
- }
- public function getAction() {
- return $this->action;
- }
- public function getParams() {
- return $this->params;
- }
- }
- $uri = filter_var(rtrim(isset($_GET['url']) ? $_GET['url'] : null, '/'), FILTER_SANITIZE_URL);
- $router = new Router($uri);
- $router->map();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement