Guest User

Untitled

a guest
Aug 2nd, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. class App
  4. {
  5.  
  6. protected $controller = 'home';
  7. protected $method = 'index';
  8. protected $params = [];
  9.  
  10. public function __construct()
  11. {
  12. $url = $this->parseUrl();
  13. var_dump($url);
  14.  
  15. if(file_exists('../app/controllers/'.$url[0].'.php'))
  16. {
  17. $this->controller = $url[0];
  18. unset($url[0]);
  19. }
  20.  
  21. require_once '../app/controllers/'.$this->controller.'.php';
  22. $this->controller = new $this->controller;
  23.  
  24. if(isset($url[1]))
  25. {
  26. if(method_exists($this->controller, $url[1]))
  27. {
  28. $this->method = $url[1];
  29. unset($url[1]);
  30. }
  31. }
  32.  
  33. $this->params = $url ? array_values($url) : [];
  34. call_user_func_array([$this->controller, $this->method], $this->params);
  35. }
  36.  
  37. public function parseUrl()
  38. {
  39. if(isset($_GET['url']))
  40. {
  41. return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
  42. }
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment