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?
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 theonBootstrapmethod of the module class, and theEvent Manager. Realistically, most bootstrapping is no longer needed; it's been replaced by entries in theService Managerand event hooks, but as an example, here is how you can perform module level bootstrapping by using theonBootstrapmethod ofModule.php:
public function onBootstrap(\Zend\Mvc\Event $e)
{
$myService = $e->getApplication()->getServiceLocator()->get('my-service');
$myService->doBootrappingCode();
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With