Can't get CI2 packages to load.. - 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: Can't get CI2 packages to load.. (/showthread.php?tid=36649) |
Can't get CI2 packages to load.. - El Forum - 12-09-2010 [eluser]stormbytes[/eluser] I've got a 'curl_demo' controller that makes a load call to a library 'curl_fetch'. Curl_Fetch has 2 dependency files, 'curl.php' & 'curl_result.php', located in /Application/third_party/curl/. When I load the controller, CI generates an Error. Unable to load the requested class: curl What's wrong with this picture? The Controller: Code: class Curl_demo extends CI_Controller Curl_Fetch Library constructor: Code: class Curl_Fetch Can't get CI2 packages to load.. - El Forum - 12-09-2010 [eluser]stormbytes[/eluser] Okay well.. Had no choice but to create a folder in Application/Libraries/. The add_package_path() isn't working for me. Thought it might have something to do with the way I was making the call ($CI vs. $this from within a controller) but after some testing it made no difference. Strange... the syntax is right out of the UG. Bug?? Can't get CI2 packages to load.. - El Forum - 12-10-2010 [eluser]Phil Sturgeon[/eluser] There are plenty of things that this could be. Is your file: application/third_party/curl/Curl.php? Libraries are required to have a capitol letter so make sure you're doing that. Can't get CI2 packages to load.. - El Forum - 12-10-2010 [eluser]stormbytes[/eluser] Just for the hell of it, I decided to test it out - I created a class called 'Test.php' and placed it into /Application/third_party/ Code: <?php if (!defined('BASEPATH')) exit('No direct script access'); Then I created a controller called 'testing.php', and placed it in my controllers folder. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access'); Then I tried to load up the controller in a browser, by going to localhost/Test (for some odd reason 'localhost/test' didnt' resolve), and I got: "An Error Was Encountered Unable to load the requested class: test" Can't get CI2 packages to load.. - El Forum - 12-10-2010 [eluser]Phil Sturgeon[/eluser] Load in the same way but move your libraries into a "libraries" folder. application/third_party/libraries/curl/Curl.php Otherwise, how would it know it's a library? Can't get CI2 packages to load.. - El Forum - 12-10-2010 [eluser]stormbytes[/eluser] Phil - First off, thanks for the tip! It worked like a charm, but truthfully, I've come to expect that from Phil Sturgeon Now for the caveats: [quote author="Phil Sturgeon" date="1292009005"]Load in the same way but move your libraries into a "libraries" folder. application/third_party/libraries/curl/Curl.php Otherwise, how would it know it's a library? [/quote] Actually, that's not even a little intuitive. In fact, if anything, the manual is misleading. First off, it makes no mention at all of libraries having to be in a 'libraries' folder. if anything, the opposite is indicated! Here's an excerpt right from the UG/Loader Class: Code: An application package allows for the easy distribution of complete sets of resources in a single directory, complete with its own libraries, models, helpers, config, and language files. It is recommended that these packages be placed in the application/third_party folder. Below is a sample map of an package directory And here's a sample, showing very clearly that a 'library' is called, while no libraries folder is required: Code: $this->load->add_package_path(APPPATH.'third_party/foo_bar/'); Finally, any thought on my part that 'Library' might somehow actually mean LIBRARY and not a synonym for 'class' is altogether dispelled by the following: Code: Note: We use the terms "class" and "library" interchangeably. While I know resources are thin nowadays, I think that documentation (especially of v2 features) is just as important to the user community as a sound code base. Can't get CI2 packages to load.. - El Forum - 12-10-2010 [eluser]Phil Sturgeon[/eluser] Well ok, a library is a class and a class is what we call libraries, because they are classes. I pointed out that classes and libraries are a little different in another thread, but only in that a library is a class loaded through the $this->load->library() and can only accept an array as a constructor. Other than that they are the same thing. As for the confusion in the documentation, is it that confusing? "resources in a single directory, complete with its own libraries, models, helpers, config, and language files." Right, so you pick a folder, then it has libraries/, helpers/, config, etc. It does exactly what it says on the tin |