Location: PHPKode > projects > Phpwebpad > phpwebpad/index.php
<?
/** -------------------------------------------------------------------------------------*
* Version: 1.0                                                                           *
* License: http://phpwebpad.hafij.com @copyright from 2010                               *
* ---------------------------------------------------------------------------------------*
* DEVELOPED BY                                                                           *
* Mohammad Hafijur Rahman (Badal)                                                        *
* hide@address.com, hide@address.com                                             *
* ------------------------------------------------------------------------------------ **/

/**
 * Start of session
 */
session_start();

/**
 * We are strict with noticable problem
 * for the script. So we are defining our
 * own error handler for noticable problem
 * in our script.
 */
function error_notice($num, $str, $file, $line) {
  echo("$str in $file line $line");
}
set_error_handler("error_notice", E_NOTICE);

/**
* Defining path for this framework. 
*/
if(!defined('ORM')) define("ORM", "bin/orm/");
if(!defined('MODEL')) define("MODEL", "application/model/");
  
define("BIN", "bin/");
define("CORE", "bin/core/");
define("LIB", "lib/");
define("APPLICATION", "application/");
define("CONTROLLER", "application/controller/");
define("VIEW", "application/view/");
define("LAYOUT", "application/layout/");
define("ELEMENT", "application/element/");
define("ROOT_CONTROLLER_NAME", "Controller");

/**
 * Configurable variable.
 * Controller name convension:
 * Allowable name : User, User_settings, Usersettings,
 * Not allowable name: UserSettings, userSettings, User_Settings
 * ---------------------------------------------------
 * This controllername is going to have 'Controller' suffix
 * at the end of its name.So the controller class name become
 * like these: UserController, User_settingsController
 * ---------------------------------------------------
 * File name: The class name should be the file name.
 * e.g: UserController.php, User_settingsController.php
 */
define("DEFAULT_CONTROLLER_NAME", "Application");

/**
 * Configurable variable. Any action name should 
 * be in small leters. The view file names and the
 * layout file names should also be in small leters.
 */
define("DEFAULT_ACTION_NAME", "index");
define("DEFAULT_LAYOUT_NAME", "layout");

/**
* This index.php file is the starting point of all the requests have been 
* maid to this server. All the request will be redirected to this file except
* the requests for the content inside the web file. It will load Request class to handle
* a new request. Then send the request to the Router to be able to pass throw
* controler.
*/
include_once(CORE."Request.php");
include_once(CORE."Router.php");

/**
* Process the server request into a valid request. Then pass the 
* recognizable request to the router and start the router in order
* to render the controller.
*/
Request::parse($_SERVER['REQUEST_URI']);

/**
* Add special route first.
* Then start the router.
*/
Router::start();

/**
* autoload for model classes.
* load by demand
* Since we dont want to include our model class
* by ourselves. This __autoload($class) function will
* do the work for us. It will include the required class
* automatically.
* @param string $class
* @exception if the class not found.
*/
function __autoload($class){
  if(!defined('MODEL')) define("MODEL", "application/model/");
  if(!defined('ORM')) define("ORM", "bin/orm/");
  
  if(file_exists(ORM.$class.'.php') == true) {
    include_once(ORM.$class.'.php');
  } else if(file_exists(MODEL.$class.'.php') == true) {
    include_once(MODEL.$class.'.php');
  } else if(file_exists(CONTROLLER.$class.'.php') == true) {
    include_once(CONTROLLER.$class.'.php');
  } else {
    die('Class '.$class.' can not be found.');
  }

  // Setting up the mode to create table autometically.
  // That is why we set the first paramenter as true.
  // Since we are in development mode we dont allow to
  // create or alter table only once. That is why set
  // the seconde paramter as false.
  // Database::setCreateTableMode(true, false);

  // Singletone database connection.
  // $database = Database::getInstance('localhost', 'story', 'root', '');
}

/**
 * Same as sprintf but it will wrap the value.
 * @return query string
 */
function sql() {
  $args = func_get_args();
  $params = "";
  for($i = 1; $i<count($args); $i++) {
      $params = $params. 'Database::wrapValue(\''.$args[$i].'\'), ';
  }
  $params = rtrim($params, ", ");
  if(empty($params)) $php = 'sprintf(\''.$args[0].'\');';
  else $php = 'sprintf(\''.$args[0].'\', '.$params.');';
  $str = eval('return '. $php);
  return $str;
}
?>
Return current item: Phpwebpad