Advertisement
Guest User

Untitled

a guest
Oct 7th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Map structure:
  2. --controllers
  3. --models
  4. --utils
  5. controller.php //namespace Utils
  6. model.php // namespace Utils
  7. router.php // namespace Utils
  8. --views
  9. index.php
  10.  
  11. index.php:
  12. new Router()
  13.  
  14. router.php:
  15. <?php
  16. namespace Utils;
  17.  
  18. use Utils\Router;
  19.  
  20. class Router {
  21.  
  22. public function __construct() {
  23. if(isset($_GET['page']) && preg_match("/[a-zA-Z0-9]$/", str_replace("/", "", $_GET['page']))) {
  24.  
  25. $parts = array_filter(explode('/', $_GET['page']), 'Utils\Router::modifiedsplit');
  26. $class_name = array_shift($parts);
  27. if(class_exists($class_name)) {
  28. $controller = new $class_name;
  29. $controller = ucfirst(strtolower($controller));
  30.  
  31. if(count($parts) > 0 && method_exists($controller, $parts[0])) {
  32. $method = $parts[0];
  33. $controller->$method();
  34. } else {
  35. $controller->start();
  36. }
  37.  
  38. } else {
  39. // TODO link to 404
  40. echo 'no class with that name found';
  41. }
  42.  
  43. } else {
  44. require 'controllers/index.php';
  45. new Controllers\Index().start();
  46. }
  47. }
  48.  
  49. public static function modifiedsplit($var) {
  50. return $var != "";
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement