Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created December 2, 2011 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlemon/1423073 to your computer and use it in GitHub Desktop.
Save rlemon/1423073 to your computer and use it in GitHub Desktop.
bootstrap
class Bootstrap {
function __construct() {
$url = isset($_GET['url']) ? explode('/', rtrim($_GET['url'], '/')) : null;
if( empty($url[0]) ) {
$url[0] = 'index'; // default value
}
$file = PATH_CONTROLLERS . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
}
$controller = new $url[0];
$controller->loadModel($url[0]);
if( isset($url[1]) ) {
if( !method_exists($controller, $url[1]) {
$this->error();
}
if( isset($url[2]) ) {
$controller->{$url[1]}($url[2]);
} else {
$controller->{$url[1]}();
}
} else {
$controller->index();
}
}
function error() {
require PATH_CONTROLLERS . 'error.php';
$controller = new Error();
$controller->index();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment