When to Create a New Module in Zend Framework 2

One reader of my book recently asked me about creating modules in Zend Framework 2. Actually, every developer of a ZF2-based site earlier or later asks himself: When should I create a new module?“. 

When the site grows in size, you can benefit from using Zend Framework 2 feature called modules.

A module is an autonomous and reusable unit of your application. By default your application has the single Application module. And it is normal to put your models, views and controllers in this module.

You might need to create a new module when the following are true:

  •  If the functionality you are implementing is autonomous (has no or few dependencies on other modules of your application. For example, the user management functionality in theory can be separated in another module, because it does not depend on the rest of the application, but the application depends on it.
  • If a module can be separated from your application and concurrently used in another project. For example the user management module can be reused in another project without changes (only its configuration may require changes).

In any case, real life is complex, and you should be guided by the intuition when it seems that it is necessary to create a new module. If you think the separating a functionality in a module gives you some significant benefits, then create the module.

At the same time, you should not be abused by creating a huge number of almost empty modules, it is better to combine related functionality in a single module.


I am a software developer currently living in Tomsk, Russia. I received a PhD degree in Computer Science from Tomsk Polytechnic University in 2010. I have been professionally developing C/C++ and PHP software since 2005. I like contributing to open-source and writing programming articles for popular web resources, like CodeProject. Besides writing, I love skiing and watching Formula-1.

Tagged with: , ,
Posted in Zend Framework 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Follow ValuableThing on WordPress.com
%d bloggers like this: