avenirer / CodeIgniter-MY_Model

Base model (MY_Model) for the Codeigniter framework.
325 stars 204 forks source link

Intergration with HMVC #133

Open dannyd7139 opened 8 years ago

dannyd7139 commented 8 years ago

I'm trying to integrate HMVC and MY_Model together. Say I try to load a model from an outside module ie 'admin', I need to do the following: $this->load->model('public/product_model');

The leading public denotes the module name, followed by the model name. The problem happens with the table relations set in the model file. So MY_Model attempts to load the foreign models, however that CI instance is currently in the 'admin' module.

I've attempted to add the leading module name 'public' to the foreign_model attribute with no avail. Also doing so would cause an issue when the CI instance is currently in the 'public' module. Any possible solutions to integrating these projects together?

bpuig commented 7 years ago

If It's https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc module, I've just figured it out. Inside core/MY_Model.php you have to make an empty model that extends CI_Model, and then Avenirer's MY_Model has to extend that dummy model.

Example:

class MY_Model_1 extends CI_Model {

}

class MY_Model extends MY_Model_1 {
--- avernirer's model-----
}

And then use the relation as always: array('foreign_model' => 'public/product_model'....)

And then it works... Maybe it's not the most professional solution, but it's the one I found for the moment.

foxmedo commented 5 years ago

i don't understand why your extending the CI_Model two times ?

nunobasto commented 5 years ago

https://github.com/avenirer/CodeIgniter-MY_Model/issues/280#issuecomment-487163365

bpuig commented 5 years ago

i don't understand why your extending the CI_Model two times ?

Because it worked… black magic, I don't know anymore since I abandoned Codeigniter.

foxmedo commented 5 years ago

you abandoned Codeigniter for laravel ?

bpuig commented 5 years ago

you abandoned Codeigniter for laravel ?

Yes, much better imo. I started with CI because i came from vanilla PHP programming and this seemed an easy framework. Now I'm more experienced and I use Laravel, at the time it looked harder for me.

foxmedo commented 5 years ago

but what i don't like on laravel is his structure which change each time, and his quick evolution where packages does not follow.

As i' am buillding large scale application, i need something stable, which allow me to focus in the core business not in the framework components, in my opinion laravel is more for freelancer than companies