Max
Max

Reputation: 13334

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?

Upvotes: 10

Views: 9458

Answers (2)

edigu
edigu

Reputation: 10099

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();
}

Upvotes: 7

drew010
drew010

Reputation: 69967

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

Upvotes: 10

Related Questions