Welcome Guest, Not a member yet? Register   Sign In
How to load a model of a different module in a controller?
#1

[eluser]geshan[/eluser]
In a HMVC environment with multiple modules I need to load a model of a different module in a controller. So the controller's function should be able to load a model within the module and another model/models form other modules. How do I do that?

-Modular Extensions - HMVC has been used with a library named MY_Router.php.
#2

[eluser]Developer13[/eluser]
Access the other module's model through the other module's controller instead of direct contact with the model itself.
#3

[eluser]geshan[/eluser]
That is what I'm trying to do but there is error to access the model of a different module. Controller of Module x is not able to access model of Module Y. How to do it?
#4

[eluser]Colin Williams[/eluser]
So, let me get this straight, with ME - HMVC, you can not directly communicate with a "modules" model unless you go through the same "module's" controller? So, in order to share a model, you must develop an interface to it in the controller?
#5

[eluser]geshan[/eluser]
How do I do that? Lets assume I have a function called func() in Module Y's controller and model. How am I supposed to call it in Module X's controller??
#6

[eluser]wiredesignz[/eluser]
@geshan, Models that need to be loaded from different modules are considered shared and should be located in you application models directory.

And as D13 said, you may also load a module controller and use it to communicate with the model. This method offers additional benefits.

@Colin, maybe you should take a look for yourself.
#7

[eluser]Developer13[/eluser]
[quote author="Colin Williams" date="1224071926"]So, let me get this straight, with ME - HMVC, you can not directly communicate with a "modules" model unless you go through the same "module's" controller? So, in order to share a model, you must develop an interface to it in the controller?[/quote]

No, that is not what I said. I was offering one solution to the OP's problem. I never said, "you cannot" or "you must".
#8

[eluser]Colin Williams[/eluser]
Just seeking clarification for my friend geshan, which wired delivered.
#9

[eluser]Developer13[/eluser]
@Colin: I apologize that your interpretation of what I said was so off the mark.

@geshan: When I first started using ME, I asked wired the same question. His response was, "shut up and quit asking me questions!" Just kidding -- his response was to use the module's controller as an interface for the model. At first I thought this was kind of lame, but I got used to doing it and I do like having a single point of entry (the module's controller) to the module's models, libraries, etc. At the time, ME did not allow modules to access each other's models, but I think he has changed that behavior.

So, in short, from the outside module:

$this->load->module('module_name');

$this->module_name->method('params_if_required');

The second line is a call to the method that is set up in that module's controller that can access its own model.

Key thing is to just do what works for you.
#10

[eluser]geshan[/eluser]
Yes I got it working, thanks.

$this->load->module('module_name');

works fine till now :-).




Theme © iAndrew 2016 - Forum software by © MyBB