We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Module Development - syntax for loading your modules model

Development and Programming

FuzzyJared's avatar
FuzzyJared
43 posts
13 years ago
FuzzyJared's avatar FuzzyJared

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’);

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi FuzzyJared,

For the Models, you can take reference for the CI models http://ellislab.com/codeigniter/user-guide/general/models.html.

I hope, it would help you. Please share your further findings on it.

Best Regards,

       
FuzzyJared's avatar
FuzzyJared
43 posts
13 years ago
FuzzyJared's avatar FuzzyJared

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.

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

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,

       
FuzzyJared's avatar
FuzzyJared
43 posts
13 years ago
FuzzyJared's avatar FuzzyJared

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.