1

I really need some guidance here as this issue is pretty confusing and extremely different to understand for a beginner like myself.

I am running a WAMP server with the latest CI version.

In core/MY_Controller.php I have:

public GeneralController extend CI_Controller {
    public GeneralController() {
        parent::__construct();
        // Does some stuff
    }
}

public AuthenticatedController extend GeneralController {
    public AuthenticatedController() {
        parent::__construct();
        if(!loggedIn()) redirect("/login");
        // Does some stuff
    }
}

public UnauthenticatedController extend GeneralController {
    public UnauthenticatedController() {
        parent::__construct();
        if(loggedIn()) redirect("/home");
        // Does some stuff
    }
}

My login controller is:

class Login extends UnauthenticatedController {

So basically if they are logged in and load "/login" they will be routed to "/home".

This works perfectly on my local environment.

Once I upload it to my server and navigate to "/login" I get an infinite loop. After debugging I figured out that the Login controller loads AuthenticatedController instead of UnauthenticatedController so it keeps redirecting back to "/login" infinitely.

Well, now the inheritance is broken for some reason so I need to check if it calls both Auth and Unauth controllers. Nope. Just calls Auth even though it extends UnauthenticatedController.

I am at a loss here, I've tried everything I can imagine but as a new php programmer I thought I would pick some of your brains on things to try!

Thank you!

Solution: Check your production server php version vs. local

user1627928
  • 313
  • 2
  • 4
  • 13
  • Does `parent::__construct` work if you don't have any functions explicitly named `__construct`, but you do have a constructor? – Waleed Khan Aug 27 '12 at 14:33
  • http://stackoverflow.com/a/11876987/1260593 please read this and see if this is your problem – brightintro Aug 27 '12 at 14:35
  • @arxanas I'm not sure what you mean, but if I take it out it doesn't work. – user1627928 Aug 27 '12 at 14:42
  • @ekims 5.2.17 (production server) vs. 5.3.10 (local server). This seems to be the issue. If I upgrade my php on my production server to 5.3.10 will any code break I already have deployed? In other words, does php upgrade nicely without breaking legacy code? – user1627928 Aug 27 '12 at 14:44
  • thats impossible to answer, but you should think about the risk if it does break on the upgrade. Will you lose money? how many users will be impacted and for how long, etc... – brightintro Aug 27 '12 at 14:47
  • my upgrade from 5.2 to 5.3 went very smoothly, but it was a side project and I had absolutely no risk if it did break. – brightintro Aug 27 '12 at 14:48
  • @ekims thank you for all your help, how do I mark this as answered or do I just delete it? – user1627928 Aug 27 '12 at 14:49
  • i added the answer below or you can delete it. Your call – brightintro Aug 27 '12 at 14:51

1 Answers1

0

I also had this problem with extending core classes. My problem was that is was working on my local server, but not on my production server. I was receiving the 404 error in production, and only on my controllers that used the class extensions. After some research I noticed that my local server was running php version 5.3.x, while my production server was running 5.2.x. To fix this I had to upgrade my production server to 5.3.

To find out what version of php your site is using, place this command in your view:

<?php echo phpversion() ?>
brightintro
  • 1,016
  • 1
  • 11
  • 16