Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class Router {
  2.  
  3. private $uri;
  4. private $controller;
  5. private $action;
  6. private $params;
  7.  
  8. public function __construct($uri) {
  9. $this->uri = $uri;
  10. $this->action = 'index';
  11. $this->params = array();
  12. }
  13.  
  14. public function map() {
  15. $uri = explode('/', $this->uri);
  16. if (empty($uri[0])) {
  17. $c = new Config('app');
  18. $this->controller = $c->default_controller;
  19. } else {
  20. $this->controller = array_shift($uri);
  21. if (!empty($uri[1]))
  22. $this->action = array_shift($uri);
  23. if(!empty($uri[2]))
  24. $this->params = $uri;
  25. }
  26. }
  27.  
  28. public function getController() {
  29. return $this->controller;
  30. }
  31.  
  32. public function getAction() {
  33. return $this->action;
  34. }
  35.  
  36. public function getParams() {
  37. return $this->params;
  38. }
  39. }
  40.  
  41. $uri = filter_var(rtrim(isset($_GET['url']) ? $_GET['url'] : null, '/'), FILTER_SANITIZE_URL);
  42. $router = new Router($uri);
  43. $router->map();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement