CodeIgniter Forums
A part of my models would inherits an abstract class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: A part of my models would inherits an abstract class (/showthread.php?tid=75239)



A part of my models would inherits an abstract class - nico - 01-16-2020

Salut !

I want re-use same code for a group of model. Is it possible to make some models inherits a class and how to do this ?

In advance, thank you.


RE: A part of my models would inherits an abstract class - jreklund - 01-16-2020

Yes, make a base model and extend it.

models/Auth_model.php
class Auth_model extends MY_Model

core/MY_Model.php
class MY_Model extends CI_Model


RE: A part of my models would inherits an abstract class - nico - 01-16-2020

Thank you, but can we make few models class in core/  ?


RE: A part of my models would inherits an abstract class - jreklund - 01-17-2020

You can make as many you want.
But then I would place them in /models/ instead. As it's not going to be extended by all your models.