extend MY_Controller |
[eluser]Zawardo[/eluser]
I created a MY_Controller class, putted into core folder and it's working fine. Now i want to extend another time the controller, let's say MY_Second_controller. If i put this class into core folder and declare it as class MY_Second_controller. extends MY_Controller {..... when i try to use it with an application controller (like controller.php declared as class controller extends MY_Second_controller {...) i get an error of MY_Second_controller not found. I have inserted into config-php a piece of code to autoload class from core folder and it's working. My question is: why i had to add this autoload function? everything prefixed with MY_ should be autoloaded by default or do i have misunderstood anything?
[eluser]theprodigy[/eluser]
Can you show your code please. Show the basics of your MY_Controller, and MY_Second_Controller (and remember to put it within the code tags).
[eluser]Zawardo[/eluser]
i'll keep it simple: /application/core/MY_controller.php Code: <?php /application/core/MY_LoggedController.php Code: <?php and finally a normal application controller (into /application/controllers): Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]theprodigy[/eluser]
Quote:i’ll keep it simple:Is this a typo, or is the file named MY_controller.php (as opposed to MY_Controller.php (with a capital C))? Quote:i have error (not found) What is the exact error? It can't find MY_Controller (which MY_LoggedController is extending)? Or it can't find MY_LoggedController?
[eluser]Zawardo[/eluser]
[quote author="theprodigy" date="1305989257"] Quote:i’ll keep it simple:Is this a typo, or is the file named MY_controller.php (as opposed to MY_Controller.php (with a capital C))? Quote:i have error (not found) What is the exact error? It can't find MY_Controller (which MY_LoggedController is extending)? Or it can't find MY_LoggedController?[/quote] The first one is a typo ![]() The second one is cant't find MY_LoggedController
[eluser]InsiteFX[/eluser]
If I am not mistaken Codigniter.php only loads one MY_Controller so you should extend all your Controllers of the MY_Controller without the MY_ extension! Logged_Controller extends MY_Controller InsiteFX
[eluser]theprodigy[/eluser]
I'm not exactly sure how we are doing it at work, but we have several levels of hierarchy in the controllers. I've looked through the autoload.php, and it doesn't look like we are autoloading any of them, but have have a MY_Controller that extends CI_Controller, and then one or two controllers that extend MY_Controller, and then several controllers that extend those controllers, etc. All I can say is they aren't being autoloaded, and there isn't any require() or include() statements going on, and most of the extended controllers are in the core folder. I'll have to double check the code to see what we are doing, but I know it's possible. I do know that if you want to use the parent controller as a controller, you'll have to have it in the controllers directory. It's not URL accessible in the core directory. Same goes for Model. If all you are doing is extending it, then the core directory is fine. But if you want to actually use it (and load it) as a model, then it needs to be in the models directory.
[eluser]InsiteFX[/eluser]
I dont know if they have fixed it but before you had to use an autoload in the config.php Code: /* InsiteFX
[eluser]Zawardo[/eluser]
[quote author="InsiteFX" date="1306017226"]I dont know if they have fixed it but before you had to use an autoload in the config.php InsiteFX[/quote] thank you, i already fixed using that code (i put the link in the first post), i just wanted to know how does work CI ![]() |
Welcome Guest, Not a member yet? Register Sign In |