Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of João Mário Nedeff  >  Autoloader  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Describes an index file to be used together with this class
Class: Autoloader
Automatically load classes
Author: By
Last change: file extension
Date: 2 years ago
Size: 1,417 bytes
 

Contents

Class file image Download
/* 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