![]() |
Unable to load the requested class - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Unable to load the requested class (/showthread.php?tid=23180) |
Unable to load the requested class - El Forum - 10-02-2009 [eluser]briang[/eluser] In my application/libraries/ directory... I am trying to extend my "MY_Controller" class with a "MY_Auth" class. The MY_Controller class I have already created works great. But when I create any other classes I continually get this error: Quote:An Error Was Encountered The steps I am taking: 1) I create the file named MY_Auth.php, save it to 'application/libraries/' 2) Its code: Code: class MY_Auth extends Controller{ 3) Open the config/autoload.php and change this line to contain my new class: Code: $autoload['libraries'] = array('database','auth'); Then get the error. I don't understand how to get past this. Also, why did I not have to add MY_Controller to the $autoload[] array? And it works just fine. I have tried not adding MY_Auth, but then it errors out as well. Please help. Thank you. Brian Unable to load the requested class - El Forum - 10-02-2009 [eluser]InsiteFX[/eluser] You have the wrong name MY_Auth should be MY_Controller but the class name you can name it anything you like. Then you extend it in your new Controllers. When you save it the name would be MY_Controller in the application/libraries folder. So if you wanted an Auth contoller you would do this: class Auth extends Controller Then save it as MY_Controller in the application/libraries folder. Then when you create a new controller class New extends Auth Enjoy InsiteFX Unable to load the requested class - El Forum - 10-02-2009 [eluser]briang[/eluser] Thanks for the reply InsiteFX. So you can only create a MY_Controller.php for application/libraries/ ? No other library files can be created along with it? Unable to load the requested class - El Forum - 10-03-2009 [eluser]InsiteFX[/eluser] No you can create other libraries but you can only have one MY_Controller But you can have different directories see the CodeIgniter user guide here: Managing your Applications Enjoy InsiteFX Unable to load the requested class - El Forum - 10-03-2009 [eluser]briang[/eluser] I read through the information contained in the Managing your Applications link. Though didn't see anything relating to this issue. Must the other files contained in applications/libraries/ also have the "MY_" prefix? (Or whatever it is defined as in config). It seems I cannot load any classes except what is defined in "MY_Controller.php". Attempting to load any other class with a different file name continually brings up this error: Quote:An Error Was Encountered Thanks again for your help, InsiteFX. Brian Unable to load the requested class - El Forum - 10-03-2009 [eluser]briang[/eluser] OK, I think I understand the "MY_" prefix better now. It is only for extending native CI classes. Other than that, library files do not need the prefix. Correct? I was trying to (excuse my terminology) "double extend" the Controller. Theoretically, I was trying to do this: "Auth extends MY_Controller extends Controller". Was attempting this by creating an Auth.php that extends MY_Controller, while having the MY_Controller.php extend Controller. Then in application/controllers/, create a controller class 'New extends Auth', to gain a level of authentication. Unable to load the requested class - El Forum - 10-03-2009 [eluser]n0xie[/eluser] [quote author="briang" date="1254588014"]OK, I think I understand the "MY_" prefix better now. It is only for extending native CI classes. Other than that, library files do not need the prefix. Correct? I was trying to (excuse my terminology) "double extend" the Controller. Theoretically, I was trying to do this: "Auth extends MY_Controller extends Controller". Was attempting this by creating an Auth.php that extends MY_Controller, while having the MY_Controller.php extend Controller. Then in application/controllers/, create a controller class 'New extends Auth', to gain a level of authentication.[/quote] This can be achieved, but you have to let CI know where your Auth base controller is. The 2 most methods is adding it to MY_Controller or adding an include in MY_Controller: Code: // method 1 Once you have this in place you can build controllers like you would expect: Code: // admin.php in your controller folder Hope this clears things up. Unable to load the requested class - El Forum - 10-03-2009 [eluser]briang[/eluser] Perfect! Thanks n0xie. |