I just started creating a new ZF2 application for a new project based on the ZF2 skeleton, and I look at their Models tutorial .
tl; dr: how do I share a model between several different modules, placing it somewhere on a higher level (external / module)?
We have several modules configured as follows:
/
/module/ModuleName
/module/ModuleName/config
/module/ModuleName/src
/module/ModuleName/src/ModuleName
I was just about to set up the folder /module/ModuleName/src/ModuleName/Model/TableName.php, but then I realized: this table should be available in other modules. So what should I do?
Should I put the Models folder in /module/Model, or this will be the result of it being processed as a module, i.e. the .com / model site (based on our current configuration, it will be).
Should I copy and paste models between places? Should I embed models back in /vendor/library/Company/Modelsomewhere? Not quite sure if there is a best practice for this!
Question 2: The tutorial also suggests using the ServiceManager to instantiate database models to use the same instance. What if I have a module with 5 controllers, and each controller gets access to completely separate tables (say, 4 tables)? It seems to me that it will redundantly initialize 16 tables at each page load (for other controllers in this module). One table initialization adds 55 ms to pageload. Is there any way around this ?? I'm not sure how to move the configuration into controller actions based on what the tutorial does to initialize tablegateway?