![]() |
Extending a controller with __construct not working - 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 a controller with __construct not working (/showthread.php?tid=25697) |
Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]flaky[/eluser] I don't know how to ask better so I'll try to be as clear as possible I'm using HMVC and Template Library I have this controller which I want every other controller to extend, I know I could have used MY_Controller, but I prefer it this way. Path of main.php - /system/application/controllers/main.php Code: <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); An example of another controller extending the Main controller path of user.php - /system/application/modules/user/controllers/user.php Code: <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); As you can see from sample code, like this it works without a problem, but the moment I change the constructors to "__construct()" it is just giving me the 500 error. I just want to make my app as PHP5 friendly as possible. Is there a solution to this (which I'm not aware of) ?. Thanks in advance. Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]überfuzz[/eluser] I guess you've checked, but are you sure you're running on php5..? Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]flaky[/eluser] Yes Running on PHP 5.3 Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]flaky[/eluser] There is sth strange. The controllers extending main can have their constructors like "__construct()" or "User()" but the Main controller only works with "Main()" constructor and not with "__construct()". Strange. Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]frist44[/eluser] Did you try using it for the parent call too? I don't know if this is the problem, but I'm looking at my MY_Controller.php and it has something like this: Code: class Main extends Controller{ Extending a controller with __construct not working - El Forum - 12-21-2009 [eluser]theprodigy[/eluser] if the child class is calling Code: parent::__construct(); then the constructor of the parent needs to be in __construct() format, not { className }() format (as far as I know). If you change your child to call Code: parent::__construct(); Code: public function __construct() Try making all your constructors (from children controllers on up to -and including- main) Code: public function __construct(){ Extending a controller with __construct not working - El Forum - 12-22-2009 [eluser]flaky[/eluser] Yep, this was the solution. Should have realized it myself. Thanks. :-) |