Monday, April 18, 2011

Bootstrapping in Zend Framework

In Zend Framework basically request is handled as follows:

   1. Application bootstrapping
   2. Routing
   3. Dispatch

"Bootstrapping" was handled by Zend_Application after that the route(module, controller, and action were requested) was identified in "Routing".  .

In general bootstrapping creates a single entry point for our whole application so it makes our application at the start itself "getting it ready to execute". It'll load all our necessary files as soon as the routing & dispatch is done.


For modules, before routing and dispatch we need some things set up:
  • Autoloading support for module resources( view helpers, access to models, access to forms, etc. ) and it'll be enabled by default.
  • Setting up module-specific routes. During bootstrapping and before routing occurs this will be specified.
  • Module-specific navigation elements. This usually goes hand-in-hand with your routes (most Zend_Navigation pages utilize named routes).
  • Setting up module-specific plugins. If there is functionality your module may be needing to enable as part of the routing/dispatch cycle, set this up in plugins and attach them to the front controller.
In the modular structure we can even specify separate bootstrap file for each module. So that we can do things specific to each modules and also we have a master bootstrap file to get full control.


FYI: I have come across one good PDF which explains all about ZF dispatch process - zenddispatch_en.pdf

Here is the exaple for config.ini file.

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

autoloaderNamespaces[] = "Plugin"
autoloaderNamespaces[] = "Helpers"
autoloaderNamespaces[] = "Validator"

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 1
resources.frontController.params.prefixDefaultModule = "1"

resources.frontController.actionhelperpaths.Helper_Action = APPLICATION_PATH  "/../library/Helpers/Action"


resources.modules[] =
resources.view[] =
resources.view.helperPath.Helper_View = APPLICATION_PATH "/../library/Helpers/View"

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "username"
resources.db.params.password = "password"
resources.db.params.dbname = "database_name"
resources.db.params.charset = "utf8"
resources.db.params.driver_options.1002 = "SET NAMES utf8"
resources.db.isDefaultTableAdapter = true


resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"


[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

2 comments:

  1. can u please explain with some example for bootstrapping

    ReplyDelete
  2. Sure i'll add a sample bootstrap file along with example soon and thanks....

    ReplyDelete