Previous Next

Available Resource Plugins

Here you'll find API-like documentation about all resource plugins available by default in Zend_Application.

Zend_Application_Resource_Db

Zend_Application_Resource_Db will initialize a Zend_Db adapter based on the options passed to it. By default, it also sets the adapter as the default adapter for use with Zend_Db_Table.

The following configuration keys are recognized:

  • adapter: Zend_Db adapter type.

  • params: associative array of configuration parameters to use when retrieving the adapter instance.

  • isDefaultTableAdapter: whether or not to establish this adapter as the default table adapter.

Example #1 Sample DB adapter resource configuration

Below is an example INI configuration that can be used to initialize the DB resource.

[production]
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "webuser"
resources.db.params.password = "XXXXXXX"
resources.db.params.dbname = "test"
resources.db.isDefaultTableAdapter = true

Note: Retrieving the Adapter instance

If you choose not to make the adapter instantiated with this resource the default table adapter, how do you retrieve the adapter instance?

As with any resource plugin, you can fetch the DB resource plugin from your bootstrap:

$resource = $bootstrap->getPluginResource('db');

Once you have the resource object, you can fetch the DB adapter using the getDbAdapter() method:

$db = $resource->getDbAdapter();

Zend_Application_Resource_Frontcontroller

Probably the most common resource you will load with Zend_Application will be the Front Controller resource, which provides the ability to configure Zend_Controller_Front. This resource provides the ability to set arbitrary front controller parameters, specify plugins to initialize, and much more.

Once initialized, the resource assigns the $frontController property of the bootstrap to the Zend_Controller_Front instance.

Available configuration keys include the following, and are case insensitive:

  • controllerDirectory: either a string value specifying a single controller directory, or an array of module to controller directory pairs.

  • moduleControllerDirectoryName: a string value indicating the subdirectory under a module that contains controllers.

  • moduleDirectory: directory under which modules may be found.

  • defaultControllerName: base name of the default controller (normally "index").

  • defaultAction: base name of the default action (normally "index").

  • defaultModule: base name of the default module (normally "default").

  • baseUrl: explicit base URL to the application (normally auto-detected).

  • plugins: array of front controller plugin class names. The resource will instantiate each class (with no constructor arguments) and then register the instance with the front controller.

  • params: array of key to value pairs to register with the front controller.

If an unrecognized key is provided, it is registered as a front controller parameter by passing it to setParam().

Example #2 Sample Front Controller resource configuration

Below is a sample INI snippet showing how to configure the front controller resource.

[production]
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleControllerDirectoryName = "actions"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultControllerName = "site"
resources.frontController.defaultAction = "home"
resources.frontController.defaultModule = "static"
resources.frontController.baseUrl = "/subdir"
resources.frontController.plugins.foo = "My_Plugin_Foo"
resources.frontController.plugins.bar = "My_Plugin_Bar"
resources.frontController.env = APPLICATION_ENV

Example #3 Retrieving the Front Controller in your bootstrap

Once your Front Controller resource has been initialized, you can fetch the Front Controller instance via the $frontController property of your bootstrap.

$bootstrap->bootstrap('frontController');
$front = $bootstrap->frontController;

Zend_Application_Resource_Modules

Zend_Application_Resource_Modules is used to initialize your application modules. If your module has a Bootstrap.php file in its root, and it contains a class named Module_Bootstrap (where "Module" is the module name), then it will use that class to bootstrap the module.

By default, an instance of Zend_Application_Module_Autoloader will be created for the module, using the module name and directory to initialize it.

Since the Modules resource does not take any arguments by default, in order to enable it via configuration, you need to create it as an empty array. In INI style configuration, this looks like:

resources.modules[] =

In XML style configuration, this looks like: