If a controller is central, then how do other controllers (which are coded to be the center of the request) interact with the infrastructure?
Well, it is a hard question. I will try to explain my opinion. Sorry if my english is not that good. Sometimes I can’t explain exactly what I’m thinking… But thank you for your patience and for your valuable help! 😊
The modules could be exactly like controlers in their structure and also be in the same folders the controllers are. But, the modules won’t need to be called directly by the URI. They could be like “private classes” (ie private controllers), maybe their names can start with a trailling underscore too, I don’t know. Modules should be designed to be loaded directly by views or by controllers, injecting them into views.
When a view is rendered, the module index() function should always be executed and it will return the result to the view it belongs. It can also have its own models and subviews, and these subviews will can load their submodules, making the whole thing hierarchyly.
The main problem here, I think, is how to control the flow to execute some desired function inside any desired module… Normally this thing is up to the developer to resolve, not to the framework. It will becomes even more complicated if we have the same functions names in different loaded modules. I really don’t know how an HMVC solve this issue.
Imagine an URI like this:
<a href="http://www.mysite.com/[folder/]controller/[module/[submodule/]]function/parameter1[/parameter2]">http://www.mysite.com/[folder/]controller/[module/[submodule/]]function/parameter1[/parameter2]</a>;
I can’t figure out how the engine could manage this. It must load only the controller and pass to it what function will be executed, in what module. And also, if I call a function of my controller that have the same name of a module, how the engine will know what thing is to be called?
So, forget everything I have said until now. I am always in favor of simplicity.
I just need to load my modules from my views and execute them. No need to more than that. Anything more special I can do in my controllers, which was designed to this purpose. The modules are just partials, that I want to reuse their code everytime I want in my application.
For example, imagine a page where I load the same module twice. It must be loaded only once, but it need to be executed two times. When I load it, I can pass parameters to it, so each execution of the same module can deal with different data.
It seems to me that you need to come up with a module that on instantiation takes off with it’s piece of the pie so that your controller or view ( I say view since it looks like you are loading your modules from your view ) only need to instantiate your module and that put’s your module on auto pilot.
Exactly! The idea is to load a module and it be independently from the rest, but with full access to the CI resources, like controllers have.
Seems to me you could do that just by changing your index methods in your modules to the constructor, just make sure that if you are basing your module design on a superclass similar to my module superclass that you first call the superclass constructor.
Hmmm… It is more clear for me now. But isn’t in some way possible to modules extend the controller instead of a module superclass? Is there any way to use $this->load->model() and $this->load->view() instead of $this->ci->load->model() and $this->ci->load->view()? I would like to have something more standard, working like anything else in CI.