Extending 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 Controller (/showthread.php?tid=7041) |
Extending Controller - El Forum - 03-21-2008 [eluser]Kemik[/eluser] Hello, If I extend the controller, e.g. class Public_Controller extends Controller and then class User_Controller extends Public_Controller. E.g. Code: class Public_Controller extends Controller { Will I be able to use $query0 from the Public_Controller in a controller whos parent is User_Controller? I've tried it atm but it just says Fatal error: Call to a member function on a non-object on the line that calls $query0. Is there a way to fix this or do I need to put the query in each extension? Extending Controller - El Forum - 03-21-2008 [eluser]wiredesignz[/eluser] Make $query0 a class var of the parent class, its then available in extended classes as $this->query0; or better yet make the $data array a class var. Extending Controller - El Forum - 03-21-2008 [eluser]Derek Jones[/eluser] Code: function User_Controller() { You'll want to call your extended class's constructor, not the original Controller() constructor, or your extended class's constructor will never execute e.g.: Code: function User_Controller() { Extending Controller - El Forum - 03-21-2008 [eluser]wiredesignz[/eluser] I never noticed that!!, good call Derek. Extending Controller - El Forum - 03-31-2009 [eluser]dieter[/eluser] I have a similar issue: Situation: Code: MY_Controller extends Controller () { ... } Code: class Controller_A extends MY_Controller Works fine Code: class Controller_B extends Controller_A Doesn't work: Fatal error: Class 'Controller_A' not found in (...) Any ideas or suggestions to solve this? Thanks, Dieter Extending Controller - El Forum - 03-31-2009 [eluser]louis w[/eluser] [quote author="dieter" date="1238508108"]I have a similar issue: Doesn't work: Fatal error: Class 'Controller_A' not found in (...) Any ideas or suggestions to solve this? Thanks, Dieter[/quote] Do you have an include_once('Controller_A.php'); before you try to extend it? Extending Controller - El Forum - 05-24-2009 [eluser]Nexus Rex[/eluser] I also have a similar issue: File: system/application/libraries/My_controller.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); When I try to create a members controller that extends My_controller I get an error. FATAL ERROR: Class 'My_controller' not found in /home/latinole/public_html/directory/system/application/controllers/members.php on line 3 I have tried autoloading the library, moving it to /system/application/controllers/, all to no avail. Extending Controller - El Forum - 05-24-2009 [eluser]Dam1an[/eluser] The file should be called MY_Controller.php, although this is only an issue if you're using Linux as its case sensitive Extending Controller - El Forum - 05-24-2009 [eluser]Nexus Rex[/eluser] Simple mistake - thank you! |