![]() |
Using a library class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Using a library class (/showthread.php?tid=20569) |
Using a library class - El Forum - 07-14-2009 [eluser]Ikkaku-Sama[/eluser] Hi! I'm trying to create a file called GeneralModel.php, because my models have the same functions and I want to put them into one file to my Models extend this GeneralModel. I tried to put it at this folder: system/application/models, but it wasn't right. I read the CodeIgniter Tutorial and now I'm putting my GeneralModel.php at the libraries folder. But, when I tried to extend GeneralModel, generated this error: Fatal error: Class 'GeneralModel' not found in C:\wamp\www\myProject\system\application\models\programasModel.php on line 2 I loaded my GeneralModel at the autoload.php and now appears this error: Fatal error: Class 'Model' not found in C:\wamp\www\myProject\system\application\libraries\GeneralModel.php on line 2 My General insn't finding my the class Model. How can I solve this? Is it right what I'm doing? Using a library class - El Forum - 07-14-2009 [eluser]Kepler[/eluser] Did you code GeneralModel as: Code: class GeneralModel extends Model { And ProgramasModel.php as: Code: <?php And set autoload.php as: Code: $autoload['libraries'] = array(...,'generalmodel'); I tried it and it works for me. Using a library class - El Forum - 07-14-2009 [eluser]Johan André[/eluser] Use MY_Model.php in libraries folder instead. It's for extending models. MY_Model.php Code: class MY_Model extends Model Then let your models extend MY_Model instead of Model. Using a library class - El Forum - 07-15-2009 [eluser]Ikkaku-Sama[/eluser] [quote author="Johan André" date="1247636222"]Use MY_Model.php in libraries folder instead. It's for extending models. MY_Model.php Code: class MY_Model extends Model Then let your models extend MY_Model instead of Model.[/quote] Thank you, Johan André. Your solution solved my problem. |