CodeIgniter Forums
Advice needed. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Advice needed. (/thread-38562.html)



Advice needed. - El Forum - 02-11-2011

[eluser]chefnelone[/eluser]
Hello,

I need some advice on this.

I have a site which has a front-end and and a back-end part.

I created a MY_Models file which I'm using to extend all models used in the back-end.

Now I'd like to extend the models used for the front-end to MY_Model too. But as I see, every time a fron-end model is called I'll loading all the functions which are nedded for the back-end. Plus, it's not clear to have all function in just one file.

Can I extend the front-end model to other model? This is: Can I have 2 MY_Models, one to extend back-end models and one to extend front-end models?

Hope someone understand what I mean.

Thanks


Advice needed. - El Forum - 02-11-2011

[eluser]Rolly1971[/eluser]
What you could do is have 3 primary models:

MY_Model - This should only have functions that are gonna be common to everything.
Admin_Model - Functions for your back end, extends MY_Model
Public_Model - Functions for the front end, extends MY_Model

then load the appropriate model as needed.


Advice needed. - El Forum - 02-12-2011

[eluser]chefnelone[/eluser]
[quote author="Rolly1971" date="1297475424"]What you could do is have 3 primary models:

MY_Model - This should only have functions that are gonna be common to everything.
Admin_Model - Functions for your back end, extends MY_Model
Public_Model - Functions for the front end, extends MY_Model

then load the appropriate model as needed.[/quote]

I put the 3 of them: MY_Model, Admin_Model and Public_Model in: application/libraries/ (I'm still in ci1.7)
And I have Back_Model in application/models

Then I call back_Model which extends to Admin_Model which extends to MY_Model:

Code:
<?php     //in application/models
class Back_Model extends Admin_Model{
...

Code:
<?php   //in application/libraries
class Admin_Model extends MY_Model{
...

Code:
<?php   //in application/libraries
class MY_Model extends Model{
...

but I get this error:

Code:
ErrorException [ Fatal Error ]: Class 'MY_Model' not found
APPPATH/libraries/Admin_Model.php [ 2 ]
1 <?php  
2 class Admin_Model extends MY_Model{

Is this what you meant?
What's wrong?


Advice needed. - El Forum - 02-12-2011

[eluser]InsiteFX[/eluser]
Back and Admin should both extend from MY_Model.

MY_Model should everything that is used in all extended models.

InsiteFX


Advice needed. - El Forum - 02-15-2011

[eluser]chefnelone[/eluser]
[quote author="InsiteFX" date="1297530766"]Back and Admin should both extend from MY_Model.

MY_Model should everything that is used in all extended models.

InsiteFX[/quote]
ok, then I understand that is not possible to have 2 extended models chained?


Advice needed. - El Forum - 02-15-2011

[eluser]InsiteFX[/eluser]
Once you setup your models like above you can extend all other models form back or admin!

InsiteFX