简体   繁体   中英

Zend Framework 1.11 - Register Plugins in Application.ini or Bootstrap.php?

I've been looking at various sites for Zend Framework best practices and information, and understand you can register plugins in two different ways:

Application.ini

resources.frontController.plugins.PluginName = "App_Controller_Plugin_PluginName"

and...

Bootstrap.php

$frontController->registerPlugin(new My_Controller_Plugin_ModuleLayout());

My question is, which is the best/preferred method and why?

My personal opinion is that doing it in bootstrap is a tad better. One example scenario is if you have a configurable plugin - you can call the constructor with some options of choice (which may be objects - with application.ini you won't be able to do that).

But as I stated, it's only my preference, I too would like to know if there are any best practices, so +1 for the question :)

One of the other advantage of going the Bootstrap way is the flexibility of being able to register certain plugins per modules. With Application.ini your settings applies to the whole of your application. If you have a pretty large application with couple of Plugins, you would not want all of these running every time a part of your application is requested.

I agree though that Application.ini is a tad easier to register and de-register and for different environment

Think of it this way.
When you set up an application using Zend_Tool ( ZF.bat ).
Zend provides for you a mostly complete application.ini and an empty Bootstrap.php .
I feel it's safe to assume that in most cases registering plugins in the application.ini would be considered perfectly acceptable, if not best practice.
Some plugins will always work better or easier from the bootstrap.
In the end it comes down to : Do what is best for you and your project!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM