![]() |
Custom controller for testing controllers only - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Custom controller for testing controllers only (/showthread.php?tid=17113) |
Custom controller for testing controllers only - El Forum - 03-25-2009 [eluser]Mackstar[/eluser] I have a subfolder in my controllers directory called unit testing, in here I have controllers for that purpose.. I realized 3 methods are repeater in each of them which is not DRY enough for me. I wanted to make a custom controller which could be inherited on just these controllers and not the other controllers in my app... So the MY_Controller concept I couldn't get working as it would apply to all controllers. I tried loading a test_controller class using hooks but pre_system is loaded before the controller class recognized and pre_controller already has the controller file requested even though the object hasn't been constructed so gives me errors... Is there another way to do this?? Without altering the CI system files... Many thanks Richard Custom controller for testing controllers only - El Forum - 03-25-2009 [eluser]pistolPete[/eluser] [quote author="Mackstar" date="1238047706"]So the MY_Controller concept I couldn’t get working as it would apply to all controllers.[/quote] No, you can easily control the inheritance. Have a look at this example: Code: <?php Code: <?php Code: <?php Custom controller for testing controllers only - El Forum - 03-25-2009 [eluser]Mackstar[/eluser] Thanks for the reply, yes that is great, I actually started trying this at the beginning, but it wouldn't autofind the class file and I got the following error, Fatal error: Class 'TestController' not found in /Users/Mackstar/Sites/ccs/system/application/controllers/unit_tests/testmymodel.php on line 3 I had this file in the application/libraries directory... How can I get this to autoload?? I guess from looking at your example that you recommend placing this class in the MY_Controller.php file?? Thanks again Custom controller for testing controllers only - El Forum - 03-25-2009 [eluser]pistolPete[/eluser] [quote author="Mackstar" date="1238049331"]I guess from looking at your example that you recommend placing this class in the MY_Controller.php file??[/quote] Yes, if you name the file MY_Controller.php and place it into ./system/application/libraries/ it will be autoloaded without any further ado. Custom controller for testing controllers only - El Forum - 03-25-2009 [eluser]Mackstar[/eluser] Thats great.. Have it working now... Very quick and friendly forum, I am impressed. Might just make me stick with CI long term.... |