aserwin
aserwin

Reputation: 1050

Zend Framework 2 multiple modules

If I have multiple modules in my project, for example my UI module and my database module... what determines which module is executed? There is an array in application.config.php and I was thinking that perhaps the order your module namespaces were listed in there would affect the situation, but that doesn't seem to be the case.

I know this is simple, and probably in the docs (I did look!)

TIA

Upvotes: 1

Views: 3105

Answers (1)

David
David

Reputation: 20085

In ZF2 the "application" is just a container for modules. The modules themselves are what implement the application's functionality. For instance, in the Zf2SkeletonApplication example the application's functionality (excluding assets like CSS, images, and javascript) is contained within a module called "application".

When a ZF2 project loads, all of the modules declared in application.config.php are initialized and their configurations (including routing) are merged into the parent application configuration.

Two main things determine the majority of what code gets executed when an application runs:

  1. The module initialization contained in each module's Module.php file (example from the Zf2 Skeleton). This initialization code defines the module's configuration paths, autoloading, and event handling. The initialization code needs to be as light-weight as possible for performance purposes.
  2. The routing itself defines the entry points for the majority of the rest of execution: which controllers get executed in which module. The controllers then determine much regarding what other code gets run, whether libraries provided by other modules will be run, etc.

For simplicity's sake, I have left out some of the intricacies, but this is a good general overview.

A tutorial like the ZF2 Getting Started Tutorial is quite valuable for learning the basics.


EDIT: I should note, "application level routing" is modified at the "module level", since the configs are all merged and the modules themselves implement the application.

Upvotes: 2

Related Questions