File: D:/HostingSpaces/SBogers55/frankdeturck.nl/wwwroot/lib/bootstrap.class.php
<?php
/**
* Created by Komma.pro
* User: mikevandersanden
* Date: 17/9/13
*/
class Bootstrap
{
public function __construct()
{
// Initialize the session
Session::init();
// Create a session for javascript output
$_SESSION['js_output'] = '';
// Initialize translator
$Translator = new Translator(URL_LANG);
// Get Controller
$c = 'Home';
$m = 'index';
if(defined('URL_PAGE'))
{
$pageToConvert = str_replace('?rel=ajax','',URL_PAGE);
if(! empty($pageToConvert)) $c = $Translator->convert($pageToConvert);
}
// Get method
if(defined('URL_SUB'))
{
$methodToConvert = str_replace('?rel=ajax','',URL_SUB);
$m = $Translator->convert($methodToConvert);
}
// Load
$this->load($c, $m);
}
/*
* Load a controller
* @param $c / controller
* @param $m / method
*/
private function load($name, $method)
{
// Controller file
$file = DOCUMENT_ROOT . 'app/controllers/c_' . strtolower($name) . '.class.php';
// Check if we need to load a basic page or the controller file
if(is_file($file))
{
//If the controller file exists require the file and create a new Controller object
if( ! class_exists($name))
{
require_once $file;
}
}
else
{
Fn::notFound();
}
// Basic page -> Create a controller object and load the model
$Controller = new $name;
$Controller->loadModel($name);
// Initialise the controller
$Controller->init($name);
// Call the method
if(method_exists($Controller, $method))
{
$Controller->{$method}();
return true;
}
// If nothing returned, header a 404
Fn::notFound();
return false;
}
}