index.php

The index.php file is, essentially, the main controller. It's a central access point for requests processed by Framework.

  • You can change FRAMEWORK_BASE_PATH to be another path to a directory outside of your document root. This is recommended to avoid people perusing your document root.
  • Framework::start() takes a single argument, which is the SiteClass you wish to run. You could, for instance, set up your index.php to run sites based on $_SERVER['SERVER_NAME'], which would allow you to load multiple sites from a single installation of Framework.

Example index.php

<?php

/**
 * index.php rules!
 *
 * An example controller to use with Framework. Copy this file into your 
 * website's document root to use.
 *
 * @author Joe Stump <joe@joestump.net>
 * @filesource
 */

/**
 * FRAMEWORK_BASE_PATH
 *
 * Dynamically figure out where in the filesystem we are located.
 *
 * @author Joe Stump <joe@joestump.net>
 * @global string FRAMEWORK_BASE_PATH Absolute path to our framework
 */
define('FRAMEWORK_BASE_PATH',dirname(__FILE__));

require_once('Framework.php');

// Load the Framework_Site_Example class and initialize modules, run events, 
// etc. You could create an array based on $_SERVER['SERVER_NAME'] that loads
// up different site drivers depending on the server name. For instance, 
// www.foo.com and foo.com load up Framework_Site_Foo, while www.bar.com, 
// www.baz.com, baz.com, and bar.com load up Bar (Framework_Site_Bar).
$result = Framework::start('Example');

// If a PEAR error is returned usually something catastrophic happend like an
// event returning a PEAR_Error or throwing an exception of some sort.
if (PEAR::isError($result)) {
    die($result->getMessage());
}

// Run shutdown functions and stop the Framework
Framework::stop();

?>