Extend a controller Codeigniter |
I have installed Codeigniter on IIS. Everything is going great.
I am trying to extend the CI_Controller class. The reason I am doing this is to put a security check in the constructor. Some controllers will extend the CI_Controller. Some controllers, which need to be secure will extend MY_Controller. This seems like a good approach to me. So far I have followed these instructions. Creating Core Classes But when I call a page which extends MY_Controller I get a blank page. Check the network tab in Firebug, I see "500 internal server error." I check my CI logs I see this: Quote:DEBUG - 2014-11-24 10:26:47 --> Config Class Initialized For a normal point of reference here is another page which does not extend MY_Controller Quote:DEBUG - 2014-11-24 10:27:32 --> Config Class Initialized Can anyone tell me what is wrong?
You do have application/core/MY_Controller, right?
And you are calling /stuff, where application/controllers/Stuff.php contains class Stuff extends MY_Controller? If this is the case, I suggest checking your IIS server logs for error messages. ps - Newly registered users have their first couple of posts moderated, which means that they need to be approved before showing in the forum. You do NOT need to post twice. This is an effective anti-spam measure, though time-consuming at our end.
I don't think you have your error reporting set up well, because an error causing a 500 HTTP status code will show some error, somewhere, either in output or in the logs.
Since there is no error provided, there are a couple of possible issues: - application/core/MY_Controller.php does not exist (as ciadmin suggested) - your controller is not extending MY_Controller (as ciadmin suggested) - application/core/MY_Controller.php does not extend CI_Controller - your subclass suffix is not set to "MY_" in application/config/config.php (has to be the same as your controller extension suffix, default is "MY_") - syntax or other fatal error in your MY_Controller class
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
I have the same problem with you. And I found that my file name is not same as my class name. Try to check your filename. Filename must be MY_Controller.php
Filename must be /application/core/MY_Controller.php (core dir doesn't exist by default, just create one)
It should look like: PHP Code: class MY_Controller extends CI_Controller { Then other controllers: /application/controllers/Something.php PHP Code: class Something extends MY_Controller { |
Welcome Guest, Not a member yet? Register Sign In |