My Bootstrap


SUBMITTED BY: Guest

DATE: Nov. 16, 2013, 10:10 a.m.

FORMAT: PHP

SIZE: 1.8 kB

HITS: 31536

  1. <?php
  2. class Bootstrap {
  3. function __construct() {
  4. //set error reporting
  5. //error_reporting(1);
  6. //get the current url
  7. $url = isset( $_GET['url'] ) ? $_GET['url'] : null;
  8. $url = rtrim($url, '/');
  9. $url = filter_var($url, FILTER_SANITIZE_URL);
  10. $url = explode('/', $url);
  11. //print_r($url);
  12. if( empty($url[0]) ) {
  13. require_once "Controllers/index.php";
  14. $controller = new Index();
  15. $controller->index();
  16. return false;
  17. }
  18. //check if the file exists
  19. $file = 'Controllers/' . $url[0] . '.php';
  20. if( file_exists($file) ) {
  21. require_once $file;
  22. } else {
  23. //echo "The file: $file Does not exists. ";
  24. header("Location: ".URL."notfound");
  25. exit;
  26. }
  27. //declare new instance of the controller class
  28. $controller = new $url[0];
  29. $controller->loadModel($url[0]);
  30. //check if there's an arguement
  31. if(isset( $url[2] )) {
  32. $controller->{$url[1]}($url[2]);
  33. } else {
  34. //check if the methods exist
  35. if(isset( $url[1] )) {
  36. $controller->{$url[1]}();
  37. } else {
  38. $controller->index();
  39. }
  40. }
  41. }
  42. }
  43. ?>

comments powered by Disqus