Bootstrap-ing in Zend Framework


.

Bootstrap.php inside your application directory runs before your application loads in order to process auto loading of resources. resource auto loading can be performed in two ways using either Bootstrap.php or application.ini for an application.

Bootstrap methods used as initialize-r should be of protected and begin with _init.

As an example, you want to initialize language translation resource, create a method like _initTranslation() as below:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
      protected function _initTranslation(){
      //translation enabling codes here
      }
}

bootstrap methods are named according to functionality i.e. _initLayout(), _initViewHelpers(), _initRoutes() etc.

here are two examples of bootstrap methods:

jQuery, jQuery ui/css enabler

/**
 * enable jquery, jqueryui, css
 **/
protected function _initJquery() {
  $this->bootstrap('view');
  $view = $this->getResource('view');

  //add jquery view helper path
  $view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
  //jquery lib includes here
  $view->jQuery()->enable()
       ->setVersion('1.5')
       ->setUiVersion('1.8')
       ->addStylesheet('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css')
       ->uiEnable();
}

in the above code we just enabled to make available jQuery, ui to our application.

doc type, header

/**
 * declare header, doc type etc.
 **/
protected function _initDoctype() {
   $this->bootstrap('view');
   $view = $this->getResource('view');

   //doc type
   $view->doctype('XHTML1_STRICT');
   $view->headMeta()->appendHttpEquiv('Content-type', 'text/html;charset=utf-8')
        ->appendName('description', 'test description');
   }

in the above method we declared doc type, charset etc. for our html documents belongs to the application.
.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s