error when extending CI_Controller |
[eluser]Kenneth Vogt[/eluser]
I am using CodeIgniter 2.1.0. My application/config/config.php file includes: Code: $config['subclass_prefix'] = 'MY_'; I would like to extend CI_Controller, so I created the file /application/core/MY_Controller.php with the following code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); (I realize it doesn't do anything yet, and that will kind of be the point.) I next changed my 'users' controller (which is working just fine) from: Code: class Users extends CI_Controller { to: Code: class Users extends MY_Controller { Now, when I call that controller, I get a 500 error. What am I missing?
[eluser]InsiteFX[/eluser]
It needs to be saved in ./application/core/MY_Controller.php 500 is a server error nothing to do with CodeIgniter.
[eluser]Kenneth Vogt[/eluser]
As noted above, it is saved in ./application/core/MY_Controller.php. Am I misunderstanding you? Also, while it is correct to say that 500 errors are server errors, it is not correct to say it has nothing to do with CodeIgniter. A coding mistake can easily result in a 500 error. For instance, attempt to autoload a library where the library class is missing its closing bracket: you get a 500 error.
[eluser]Kenneth Vogt[/eluser]
After upping my error reporting (thanks to the post by kb1ibh at http://ellislab.com/forums/viewthread/218167/), I got this additional information: Code: Fatal error: Class 'MY_Controller' not found in {website}/application/controllers/users.php on line 3
[eluser]InsiteFX[/eluser]
Try adding this: ./application/config/config.php! Code: /* Please read the code comments...
[eluser]Kenneth Vogt[/eluser]
I added the code above to the end of ./application/config/config.php and I still get the same error. I even tried putting a copy of MY_Controller.php at ./application/libraries. I'm stumped.
[eluser]Aken[/eluser]
If you add this to the top of your MY_Controller.php file and reload, does the message show up? Code: exit('MY_Controller.php loaded'); If so, then the file is being found, but it is not being extended properly. Perhaps you misspelt it (you didn't in your quoted code above, but maybe you changed it by mistake). If not, then the file is not being loaded, and might be a problem with the path or permissions. Make sure the folder has at least read permissions (typical CHMOD is 755 for directories that don't need write permissions). Make sure your application folder path is correct in index.php. The file is included in system/core/CodeIgniter.php somewhere around line 235 (when it works properly, lol). If you have any other code or addons that might interfere also, check those.
[eluser]Kenneth Vogt[/eluser]
It was a permissions problem. I am using PhpFog and they automatically install CodeIgniter, so I will take it up with them why anything from ./application on down is not readable. Thanks for all your help, InsiteFX and Aken. One other thing worthy of note, http://www.php.net/manual/en/language.oop5.autoload.php says: "spl_autoload_register() provides a more flexible alternative for autoloading classes. For this reason, using __autoload() is discouraged and may be deprecated or removed in the future." This applies from PHP 5.3.0, so check your PHP version. Here is an updated version of Phil Sturgeon's code: Code: spl_autoload_register(function ($class) {
[eluser]InsiteFX[/eluser]
Thank's Ken, I added it to my snippets with credit to you.
[eluser]nagata[/eluser]
Hi, I have been ssearching forum now, and found this code (Last Ken's Reply) I been wondering how to use this code? Cause when I place it in place of the old Phil's Autoloader it dosent work for me... I get this error Code: Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in C:\xampp\htdocs\application\config\config.php on line 395 |
Welcome Guest, Not a member yet? Register Sign In |