Bootstrap

The bootstrap is located at `application/bootstrap.php`. It is responsible for setting up the BootPHP environment and executing the main response. It is included by `index.php` (see Request flow)

The bootstrap is responsible for the flow of your application. In previous versions of BootPHP the bootstrap was in `system` and was somewhat of an unseen, uneditible force. In BootPHP 3 the bootstrap takes on a much more integral and versatile role. Do not be afraid to edit and change your bootstrap however you see fit.

Environment setup

First the bootstrap sets the timezone and the locale, and adds BootPHP's autoloader so the cascading filesystem works. You could add any other settings that all your application needed here.

// Sample excerpt from bootstrap.php with comments trimmed down

// Set the default time zone.
date_default_timezone_set('America/Chicago');

// Set the default locale.
setlocale(LC_ALL, 'en_US.utf-8');

// Enable the BootPHP auto-loader.
spl_autoload_register(array('BootPHP', 'auto_load'));

// Enable the BootPHP auto-loader for unserialization.
ini_set('unserialize_callback_func', 'spl_autoload_call');

Initialization and Configuration

BootPHP is then initialized by calling BootPHP::init, and the log and config reader/writers are enabled.

// Sample excerpt from bootstrap.php with comments trimmed down

BootPHP::init(array('
    base_url' => '/bootphp/',
    index_file => false,
));

// Attach the file writer to logging. Multiple writers are supported.
BootPHP::$log->attach(new BootPHP_Log_File(APPPATH.'logs'));

// Attach a file reader to config. Multiple readers are supported.
BootPHP::$config->attach(new BootPHP_Config_File);

You can add conditional statements to make the bootstrap have different values based on certain settings. For example, detect whether we are live by checking `$_SERVER['HTTP_HOST']` and set caching, profiling, etc. accordingly. This is just an example, there are many different ways to accomplish the same thing.

// Excerpt from http://github.com/isaiahdw/bootphpphp.com/blob/f2afe8e28b/application/bootstrap.php
... [trimmed]

/**
 * Set the environment status by the domain.
 */
if (strpos($_SERVER['HTTP_HOST'], 'bootphpphp.com') !== FALSE)
{
    // We are live!
    BootPHP::$environment = BootPHP::PRODUCTION;

    // Turn off notices and strict errors
    error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
}

/**
 * Initialize BootPHP, setting the default options.
 ... [trimmed]
 */
BootPHP::init(array(
    'base_url'   => BootPHP::$environment === BootPHP::PRODUCTION ? '/' : '/bootphpphp.com/',
    'caching'    => BootPHP::$environment === BootPHP::PRODUCTION,
    'profile'    => BootPHP::$environment !== BootPHP::PRODUCTION,
    'index_file' => FALSE,
));

... [trimmed]

Note: The default bootstrap will set `BootPHP::$environment = $_ENV['KOHANA_ENV']` if set. Docs on how to supply this variable are available in your web server's documentation (e.g. Apache, Lighttpd). This is considered better practice than many alternative methods to set `BootPHP::$enviroment`, as you can change the setting per server, without having to rely on config options or hostnames.

Modules

Read the Modules page for a more detailed description.

Modules are then loaded using BootPHP::modules(). Including modules is optional.

Each key in the array should be the name of the module, and the value is the path to the module, either relative or absolute.

// Example excerpt from bootstrap.php

BootPHP::modules(array(
    'database'   => MODPATH.'database',
    'orm'        => MODPATH.'orm',
    'userguide'  => MODPATH.'userguide',
));

Routes

Read the Routing page for a more detailed description and more examples.

Routes are then defined via Route::set().

// The default route that comes with BootPHP 3
Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'welcome',
        'action'     => 'index',
    ));