6

I'm new to PyroCMS and struggling to get help on the forums (slow responses, minimal activity, etc.). So, I'm hoping someone here on SO can help.

How do I share resources (e.g. models, controllers, views, etc.) between modules? It seems that every module is self contained and cannot access other modules' resources. This is going to cause a problem for us.

I do not like the idea of putting these common resources in the main PyroCMS installation. This seems architecturally wrong to me.

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441

1 Answers1

11

PyroCMS uses HMVC, so accessing resources from other modules is easy.

Let's say you want to load the model navigation_m:

This will work from within the navigation module (where it resides):

$this->load->model('navigation_m');

This will work from anywhere:

$this->load->model('navigation/navigation_m');

That's it! No need to include the model/ path, the loader takes care of it for you. Same applies to language files, libraries, and other resources.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • thanks. This now means that certain modules will be dependent on other modules for certain resources. Do you see a problem with this? – StackOverflowNewbie Jun 23 '11 at 02:38
  • If I was writing a drop-in module for Pyro I'd totally avoid dependency on other modules unless they are "core" modules and you *know* they will always be available, but if it's just for my application I wouldn't worry too much. Less dependency is better, but sometimes it's the only way to avoid code duplication. Just don't get wrapped too tight around other resources. – Wesley Murch Jun 23 '11 at 02:41
  • do you know if it's possible to create a module with multiple sub-menus? Say I am creating a "Content" module and want the sub-menus "Comments" and "Files" -- could I somehow make those 2 sub-menus appear from one module only? The reason I need to develop multiple modules is merely for those sub-menus. Seems like a bad idea to me. – StackOverflowNewbie Jun 23 '11 at 02:50
  • Not sure what you're asking, sounds like a separate question (and sounds like not a great idea, as you already seem to think). – Wesley Murch Jun 23 '11 at 02:53