CodeIgniter Forums
Can I create another Model beside MY_Model.php? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Can I create another Model beside MY_Model.php? (/showthread.php?tid=65274)



Can I create another Model beside MY_Model.php? - Phally Seng - 05-23-2016

I now have application/core/MY_Model.php that extend CI_Model. I'd need to create another MY_Article_Model.php in the same path (I'm not sure it's a good idea to create MY_Article_Model.php), but an error appeared(see my image). Can I create another model or not? If not, what Should I do?
My Folders:
- application/controllers/admin/Article.php
- application/core/MY_Model.php
- application/core/MY_Article_Model.php
- application/models/article_m.php (class Article_m extends MY_Article_Model.php) Fatal Error!


RE: Can I create another Model beside MY_Model.php? - salain - 05-23-2016

Hi,

MY_Model extend the CI_Model in order to give you some default method and properties that are not available in CI_Model.
And you create your application model like Article_model by extending MY_Model rather than CI_Model
So:
application/core/MY_Model.php extends CI_Model
application/models/Article_model.php extends MY_Model

I hope this helps.


RE: Can I create another Model beside MY_Model.php? - Phally Seng - 05-25-2016

(05-23-2016, 10:07 PM)salain Wrote: Hi,

MY_Model extend the CI_Model in order to give you some default method and properties that are not available in CI_Model.
And you create your application model like Article_model by extending MY_Model rather than CI_Model
So:
application/core/MY_Model.php extends CI_Model
application/models/Article_model.php extends MY_Model

I hope this helps.

So I understand. Thank you for your help.