When developing a custom module, what is the correct way to store and load your modules models?
I have not seen clear documentation on this other than to place the model within a models subfolder in your module.
IE - system/expressionengine/third_party/my_module/models/my_table_model.php
What is the proper syntax for loading that model then?
$this->EE->load->model(‘syntax_for_here/my_table_model’);
That reference makes sense for a CI implementation but not necessarily module/add on development. I will continue to play around with it.
In general it seems a lot of the modules developed do not follow the MVC method which is interesting since that is what code igniter really is.
Hi FuzzyJared,
You can see that Expression Engine is powered by Code Ignitor and uses almost libraries etc of Code Ignitor.
The module development also follows MVC architecture very well and one can use Code Ignitor classes very well in Expression Engine module development.
Best Regards,
I can see that it is built on codeigniter. And maybe I / the documentation is just not clear on best practices for module development within Expression Engine.
In short I am developing a series of modules for an expression engine site. In theory I should be using the following structure. system/expressionengine/thrid_party/my_module system/expressionengine/thrid_party/my_module/upd.my_module.php system/expressionengine/thrid_party/my_module/mcp.my_module.php system/expressionengine/thrid_party/my_module/mod.my_module.php system/expressionengine/thrid_party/my_module/language/english/my_module_language.php system/expressionengine/thrid_party/my_module/views/index.php system/expressionengine/thrid_party/my_module/models/my_module_table_model.php
This would be inline with the modularize mvc standpoint.
My issue was that I couldn’t find the proper include for the /models/my_module_table_model.php
The majority of the EE modules don’t use it. I finally found one that did though and saw that to include a module’s model as stored above you call it using…
$this->EE->load->model(‘my_module_table_model’);
I could have sworn that I tried this previously and it didn’t work….
Anyway the answer to my question is that you store your model files within the model folder of your module. Then call it without path reference.
While researching it seems like a lot of modules don’t follow the MVC framework. Comments within the comment module even go as far as to call it out and say that it was done due to saving on resources.
What is the expense of including models within your module development alla MVC? I like working with best practices and although not a stickler it is good to know the pros and cons so I can make judgement calls on particular modules.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.