Question

I want to write a php application using Zend Framework 2 (just the beta 2 yet).

Because it's going to be a collection of several webservices I decided to seperate it into different modules (with own databases).

Before starting to write the first module I want to write the code wich each module should need. For example the layout. Each module uses the same layout. That's why I want to write it globally to improve the development process of single modules.

How can I provide defaults for each module globally? (e.g. layout, plugin, default database model, ...)

Was it helpful?

Solution

In ZendFramework2 configurations from all modules are always merged. Additionally there is a global config which can overwrite module-wise config. So including a vendor module brings in a default configuration you can and should overwrite via your global config. The global config may consist of multiple files making it easy to distinguish between modules-to-be-configured.

The first example I have is an article of akrabat about module configuration and overrides.

Another nice example of this pattern is Akrabat's quickstart (https://github.com/akrabat/zf2-tutorial):

  • one App module, based on ZendSkeletonApp
  • one Album module, the part you actually did.

In the App module there is config for the basic routing, Views and the Layout are set up In the Album module there is only the set-up for Album-specific things (e.g. dependency injection), the view and routing are used from the App-modules config.

You may decide to overwrite this config on a per-module basis or globally, in the default project layout your configs are placed like this:

/config/application.config.php the base configuration
/config/autoload/*.config.php may be used to overwrite modules or app config (e.g. for local development)
/module/[your-module]/config/[your-module].config.php the default configuration of your module
/vendor/[vendor-module]/config/[vendor-module].config.php a module you dropped in, but has definitions for it's dependency injection. if it uses e.g. a database you want to overwrite some parameters in your /config/autoload/*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top