Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the bootstrap file in ZF2?

With ZF1 there was a bootstrap file defined under application/Bootstrap.php but I can't find it when looking at the ZF2 skeleton application.

What is the ZF2's equivalent to the ZF1 Bootstrap.php file?

like image 798
Max Avatar asked May 29 '12 13:05

Max


2 Answers

From Gary Hockin's nice article about bootstrapping and other changes in ZF2:

There is no application level bootrapping in Zend Framework 2, each module is responsible for bootstrapping it's own resources in it's Module.php. This is done using a combination of the onBootstrap method of the module class, and the Event Manager. Realistically, most bootstrapping is no longer needed; it's been replaced by entries in the Service Manager and event hooks, but as an example, here is how you can perform module level bootstrapping by using the onBootstrap method of Module.php:

public function onBootstrap(\Zend\Mvc\Event $e)
{
    $myService = $e->getApplication()->getServiceLocator()->get('my-service');
    $myService->doBootrappingCode();
}
like image 95
edigu Avatar answered Dec 04 '22 08:12

edigu


In ZF2, there is no individual Bootstrap file as there was in ZF1. You can however, add an onBootstrap() method to any of your Module classes so it will be called after loadModule.post once $application->bootstrap() is called.

On github in the ZF2 Skeleton App, the file you would add an onBootstrap() method to is located at module/Application/Module.php.

Here is some relevant documentation on Bootstrapping from the ZF2 user guide (note: any of this material is subject to change).

The MVC Bootstrap Event
Bootstrapping an Application
Bootstapping (in relation to MVC)
Sample usage of the MVC Bootstrap Event

like image 22
drew010 Avatar answered Dec 04 '22 07:12

drew010