I'm currently working on a project with CodeIgniter and its HMVC. http://jenssegers.be/projects/CodeIgniter-HMVC-Modules)
I have a general question regarding the best way to load a model in a different module. So far, I thought directly loading a model in a different module would be against MVC rule and accessed to a model indirectly by creating a function in the owner controller of the model.
For example,
class A
{
function __construct()
{
....
$this->load->model('Model_A');
}
function getUsers()
{
$this->Model_A->getUsers();
return $users;
}
}
Class B
{
....
function getModelAUsers()
{
$users_from_A = Modules::run('A/getUsers'); // This is currently how I do
$this->load->model('A/Model_A'); // This is probably how I could do.
$users_from_A = $this->Model_A->getUsers();
}
}
To be honest, creating separate functions to access a model like this is pain in the ass... and the more I code, the harder I find it to refactor. Which way is a correct one for accessing a model in a different module in MVC style? or is there another best way to do it?
One more thing. This project will be heavily refactored and updated frequently.