HMVC best practice - calling models in other modules triads? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: HMVC best practice - calling models in other modules triads? (/showthread.php?tid=33031) |
HMVC best practice - calling models in other modules triads? - El Forum - 08-13-2010 [eluser]AndyBC[/eluser] Another question related to HMVC pattern (I'm using Modular Extensions): In my database I have a 'categories' table which I need to interact with from different modules (MVC triads), eg. * Module A: Returns a 'search widget' where user can check which categories to be included in a search. * Module B: A navigational tab with links to each category. * Module C: Admin interface for creating/deleting categories The question - should I: a) implement the database interaction with the 'category' table in each module's model? This would mean duplicate code: modules A to C would all need to have a model method like 'get_categories()' doing the pretty much the same query in the db. b) Put the interaction with the categories table in it's own module - 'Categories Module' - and have the other modules call 'Categories Module' whenever categories data is needed. This seems like the right way from a maintenance point of view, but I'm not sure if this would break the HMVC philosophy of complete compartmentalizing / modularing. c) Something else? (I have read different introductions to HMVC on the net, but I can't really grasp what I'm supposed to do here) Thanks, Anders HMVC best practice - calling models in other modules triads? - El Forum - 08-13-2010 [eluser]wiredesignz[/eluser] 1. Never duplicate code. 2. Make common models available to the entire application via application/models. 3. If you must access a model in a different module, access it via a controller in that module. 4. Nobody really cares so long as it works. HMVC best practice - calling models in other modules triads? - El Forum - 08-13-2010 [eluser]AndyBC[/eluser] Thanks a lot - much appreciated ! Anders |