/* Autoloader usage
* PROJECT FOLDER STRUCTURE
* /project/Configs
* core.ini
* /Controllers
* Users.php
* /Logs
* /Models
* User.php
* /Views
* Smarty files
* /public_html
* index.php
* /library
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_DIR', realpath(dirname(__FILE__) . '/../../'));
define('PROJECT', realpath(dirname(__FILE__) . '/../'));
define('LIBRARY', ROOT_DIR . DS . 'library');
define('CONFIGS', PROJECT . DS . 'Configs');
define('LOGS', PROJECT . DS . 'Logs');
define('CONTROLLERS', PROJECT . DS . 'Controllers');
define('MODELS', PROJECT . DS . 'Models');
define('VIEWS', PROJECT . DS . 'Views');
require_once LIBRARY . 'Autoloader.php';
$autoloader = new Autoloader();
//ACTION
if(!$_GET['action'])
$action = 'Home'; // If action is empty, it is set as Home.
//Other Actions
else
$action = ucfirst($_GET['action']);
//CONTROLLER
//Home
if(!$_GET['controller'])
$controller = 'Index'; // If $controller is empty, it is set as Index controller, the default one.
//Other Controllers
else
$controller = ucfirst($_GET['controller']);
//Run
if(is_callable(array($controller, $action)))
call_user_func(array($controller, $action));
//Error
else
call_user_func(array($controller, 'Error')); // If the Controller Action is not callable thats an error, and therefore the Error action is called
|