PHP Classes

File: bootstrap.php

Recommend this page to a friend!
  Classes of Martin Barker   lightweight MVC   bootstrap.php   Download  
File: bootstrap.php
Role: Example script
Content type: text/plain
Description: The bootstrap of the MVC this controls loading of controllers and calling Actions
Class: lightweight MVC
Implements the MVC design pattern
Author: By
Last change: file names are now allways check for using lower case file names, E.G
"new library_mysql_queryBuilder" will be in file path "library/mysql/querybuilder.php"
Date: 11 years ago
Size: 1,485 bytes
 

Contents

Class file image Download
<?php
## debuging disable when not needed
##error_reporting(2047);
##ini_set("display_errors",1);
## end of debuging code

##start the sessions var
session_start();

## these are the base classes so that any class can extend them
include_once('controllers/controller.php');
include_once(
'models/models.php');
## end of critical includes

## enter custom code here it is not recomended to edit below this block ##
## end of custom code block ##

## DataStore for url params
$_URL = array();

## autoloader works like Zend_Framework's
/**
 *
 * @param string $class_name
 */
function __autoload($class_name){
   
$className = explode('_', $class_name);
   
$path = "";
    foreach(
$className as $key => $val){
       
$path .= $val."/";
    }
   
$path = substr($path, 0, strlen($path)-1);
        require_once(
strtolower($path).".php");
}
## end of autoloader
Controller::getLoadDetails($controller, $view);
$action = $view;
if(empty(
$controller)){
   
$controller = "controllers_index";
   
$view = "indexAction";
}else{
   
$controller = "controllers_".$controller;
    if(!empty(
$view)){
       
$view .= "Action";
    }else{
       
$view = "indexAction";
    }
}

try{
   
$control = new $controller;
   
$control->action = $action;
   
$control->controller = $controller;
    if(
method_exists($control, $view)){
       
$control->$view();
    }else{
       
$view = "f404Action";
       
$control->$view();
    }
}catch(
Exception $e){
   
Controller::f404Static();
}
?>