-1

Zend フレームワークではブートストラップ ファイルを使用しますが、このファイルがなくてもこのファイルが必要な理由がわかりません。プログラミング操作に大きな影響がありますか?

4

1 に答える 1

3

Bootstrap.php allows for some advanced modification that you may require for you Zend project. It is used to load common coponents or resources that are used by all or most of your controller, view, etc. Its similar to a file "common.php" that we may use in case of non-framework project.

In bootstrap you put the initial code that executes before anything else gets executed, here you can do the autoloading, initialize your plugins, setting datetimezone, etc.

There are two types of bootstrap files in Zend Framework, one has the project level scope and is placed at PROJECT_DIR/application/bootstrap.php. And the other has module level scope and is placed at PROJECT_DIR/application/modules/MODULE_NAME/bootstrap.php.

An example of the main bootstrap file (PROJECT_DIR/application/bootstrap.php) is:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
            // Initialize view
            ...
    }        
    protected function _initTimeZone()
    {
            date_default_timezone_set('Asia/Kolkata');
    }
    protected function _initAutoload()
    {
            // Add autoloader empty namespace
            $autoloader = Zend_Loader_Autoloader::getInstance();
            $autoloader->setFallbackAutoloader(true);                                        

            $admin_loader = new Zend_Application_Module_Autoloader(array(
                            'namespace' => 'Admin',
                            'basePath' =>APPLICATION_PATH . '/modules/admin'
            ));                      

            return $autoloader;     
    }
    protected function _initControllerPlugins()
    {
            // initialize your controller plugins here   
            ...            
    }

    protected function _initNavigation()
    {
            // initializing navigation
            ...                
    }
}
于 2013-08-27T04:42:09.190 に答える