CodeIgniter Forums
extend Model class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: extend Model class (/showthread.php?tid=8196)



extend Model class - El Forum - 05-08-2008

[eluser]adwin[/eluser]
Hi, i want to extend model class ... let call it extModel because I need to add some functionality that I use for all my models.

Where should I put my new class ?


extend Model class - El Forum - 05-08-2008

[eluser]FrankieShakes[/eluser]
[quote author="adwin" date="1210312535"]Hi, i want to extend model class ... let call it extModel because I need to add some functionality that I use for all my models.

Where should I put my new class ?[/quote]

adwin,

Why not create a Base_Model class that extends "Model"... and which all your models then extend:

1) Base_Model extends Model
2) My_Model extends Base_Model

You can then simply drop the Base_Model into the /Application/models directory and continue along as your normally would.


extend Model class - El Forum - 05-08-2008

[eluser]wiredesignz[/eluser]
MY_ is a reserved name and is used specifically for core extensions, in fact MY_Model would be the base model and will be automatically loaded by CI if it is placed in application/libraries, this is the class where you should place your global Model extensions.

MY_Model extends Model

All_other_models extend MY_Model


extend Model class - El Forum - 05-08-2008

[eluser]FrankieShakes[/eluser]
[quote author="wiredesignz" date="1210319610"]MY_ is a reserved name in CI used for core extensions, in fact MY_Model would be the base model and will be automatically loaded by CI if it is placed in application/libraries, this is the class where you should place your global Model extensions.

MY_Model extends Model

All_other_models extend MY_Model[/quote]

Hehehe... I totally forgot about the "MY" prefix. As I was writing my response, I was thinking of a quick and easy name for a model. For some reason "My_Model" came to mind, although it wasn't intended to imply the overriding of the default Model class.

1) Base_Model extends Model
2) Custom_Model extends Base_Model


extend Model class - El Forum - 05-08-2008

[eluser]wiredesignz[/eluser]
MY_Model located in application/libraries is still a better choice for global Model extensions as it is automatically loaded and becomes part of the core.


extend Model class - El Forum - 05-08-2008

[eluser]adwin[/eluser]
okay . thank you .. I will try at my application.
Thank you all ..