Bootstrapping the Application: the Bootstrap Class
Thursday, October 1, 2009

In addition to initialising application components via resource plugins. it is also possible to do so via the bootstrap class itself.

The bootstrap class location and name is specified in the configuration file; see Bootstrapping the Application: Configuration File Overview.

The basic skeleton of the class is as follows:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
  // Add the initialisation methods here
}

Note that Zend_Application_Bootstrap_Bootstrap is the base class; this adds the basic functionality, which essentially involves registering and initialising the front controller plugin.

The class can contain methods that initialise resources programmatically (as opposed to via the configuration file). These methods all have the prefix _init and return a reference to the resource that is initialised. The sample application contains one such method:

protected function _initAutoload()
{
  $autoloader = new Zend_Application_Module_Autoloader(array(
    'namespace' => 'Default_',
    'basePath'  => dirname(__FILE__),
  ));
 
  return $autoloader;
}

This sets up the autoloader to look for classes with the prefix Default and located in the application directory. In addition, the autoloader class automatically declares a number of additional directories and associated prefixes:

Prefix: Model_DbTable    Directory: models/DbTable
Prefix: Form             Directory: forms
Prefix: Model            Directory: models
Prefix: Plugin           Directory: plugins
Prefix: Service          Directory: services
Prefix: View_Helper      Directory: views/helpers
Prefix: View_Filter      Directory: views/filters

These prefixes and directories are applied to the base prefix and directory, and use the standard Zend Framework autoloader conventions. For instance, the class Default_Model_Db_Blog uses the prefix Default followed by the prefix Model, and is therefore located in the application/models/Db directory in a file called Blog.php; this is because the root directory, associated with Default, is application, the directory associated with Model is models, and the remaining part of the name (Db_Blog) decomposes to Db/Blog.php.

Posted by James at 6:31 pm   0 comments

Leave a Reply