1

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

3
  • Which question are you asking? The purpose seems vague. What problem are you trying to solve? Please clarify. Commented May 6, 2013 at 14:15
  • If I have 2 modules that are basically the same other than their name, which one does Zend run when I open the site? Commented May 9, 2013 at 18:29
  • All of the routing information exists WITHIN the modules themselves. There doesn't seem to be a way to manipulate routing at the application level, so how does Zend determine which module get executed when the site is loaded? Commented May 9, 2013 at 18:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

OOOOOHHHHHH! So, modules could be looked at as partial classes (a la .NET) This makes much more sense to me. Thank you.
Haha, interesting observation. They are indeed similar, while also quite different: .NET partial classes are at the language level, whereas ZF2 modules are above that at the application architecture level. You're getting the idea.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.