Extending from my own controller - 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: Extending from my own controller (/showthread.php?tid=26628) |
Extending from my own controller - El Forum - 01-19-2010 [eluser]Agustín Villalba[/eluser] Hi! Now I'm trying to extend a controller of mine which extends from CodeIgniter controller, just like this: Controller1.php class Controller1 extends Controller { function Controller1(){ parent::Controller(); } ... } Controller2.php class Controller2 extends Controller1 { function Controller2(){parent::Controller1();} This code returns this error: Fatal error: Class 'Controller1' not found in C:\xampplite\htdocs\project\system\application\controllers\Controller2.php on line XX Can any one tell me how do I extend a controller from another one?? Thank you very much!! Extending from my own controller - El Forum - 01-19-2010 [eluser]maria clara[/eluser] i haven't tried it yet but try to read the CodeIgniter User_guide. interesting to know that issue. Extending from my own controller - El Forum - 01-19-2010 [eluser]Agustín Villalba[/eluser] I have read it yet, and doesn't mention anything about this situation. Extending from my own controller - El Forum - 01-19-2010 [eluser]n0xie[/eluser] If you are running PHP5, try this: Code: // add to application/config/config.php Extending from my own controller - El Forum - 01-19-2010 [eluser]tomcode[/eluser] file Controller2.php Include the Controller1.php file before the class declaration Extending from my own controller - El Forum - 01-19-2010 [eluser]Agustín Villalba[/eluser] Thank you tomcode, I know that include solves the problem, but I'm looking for an "elegant" solution if exists. n0xie, it seems a good solution, but... how I call that function from my Controller2?? Thank you very much everyone! Extending from my own controller - El Forum - 01-19-2010 [eluser]Phil Sturgeon[/eluser] [quote author="Agustín Villalba" date="1263921899"]Thank you tomcode, I know that include solves the problem, but I'm looking for an "elegant" solution if exists. n0xie, it seems a good solution, but... how I call that function from my Controller2?? Thank you very much everyone![/quote] Instead of: Code: class Something extends Controller do: Code: class Something extends Controller1 Extending from my own controller - El Forum - 01-19-2010 [eluser]Agustín Villalba[/eluser] Hi Phil! That's what I do and that is what raise me the error: Fatal error: Class ‘Controller1’ not found in C:\xampplite\htdocs\project\system\application\controllers\Controller2.php on line XX Controller1.php class Controller1 extends Controller { function Controller1(){ parent::Controller(); } ... } Controller2.php class Controller2 extends Controller1 { function Controller2(){parent::Controller1(); } I do it just like you suggest me, but it doesn´t work!! Extending from my own controller - El Forum - 01-19-2010 [eluser]n0xie[/eluser] [quote author="Agustín Villalba" date="1263923164"] I do it just like you suggest me, but it doesn´t work!![/quote] Try this: Code: function __autoload($class) Extending from my own controller - El Forum - 01-19-2010 [eluser]Agustín Villalba[/eluser] n0xie, I know how to define that function in my config/config.php, but how I use that function in my controller2?? Thank you very much! |