What is the best way to extends MVC packages

I am looking for the best way to build re-usable MVC packages for my projects.

For example: all my projects are using User module with generic controllers, entities, forms and views to registering users (username, password and email).
My problem occurs when one customer needs an extension of register form (adding a phone number).

As my generic User module is imported and located at vendor folder, how can I make to extend it behavior?

Can you name the used vendor package? It 's hard to say, because there are plenty of good and bad practices how to or how not to extend vendor packages. It would be easier to answer if we know the used package.

Approaches you should NOT use …


Approaches you might use …

  • Write your own factories and define your own models and forms depending on your vendor package.
  • Override vendor config entries in your application config and use your own forms and models, that extend the vendor classes.


Vendor package is “Juliangorge\Users”
And my new extend module is User.

I have been trying to set factory controllers and view_manager in new module.config.php
Regarding Entity and Form, It seem I need to use listener and events (following this interesting article: Use 3rd party modules in Zend Framework 2 · Jurian Sluiman)

Hi @juliangorge,
A long time ago I wrote this post at the time of Zf2. If it helps you get some idea to add fields in LaminasUserModule this post of mine might help you in some way. My blog is not HTTPS secured. So, feel free to check it.


Even if the hint is correct, in this case nothing in the folder should be overwritten. An existing module should be extended, like adding or extending a validator of laminas-validator.

There are different ways to do this. For your register form can use the configuration. You can add the full specification to the module configuration, which allows overwriting or extending in the application.
Or you create a factory or delegator which adds new elements from the configuration.
What I often see: you extend the existing register form class and call the parent init method and add new elements. (In the configuration of your application you have to map the new form to the register form of your module.)

I would definitely keep it simple. For example, use the configuration to specify the form and you do not need custom factories, delegators, listeners, etc.

If you need a concrete code example, please ask!