Welcome Guest, Not a member yet? Register   Sign In
Multiple classes in same library
#1

[eluser]cmgmyr[/eluser]
Hello,
I'm trying to implement Rackspace's cloud files into one of my sites but it isn't working out too well so far. You can get the files here: http://github.com/rackspace/php-cloudfiles/tree

I've uploaded the 3 main files to: application/libraries/ but when I call the authentication class in cloudfiles.php the page fails.

In the cloudfiles.php file there are multiple classes. Is codeigniter having a problem with these multiple classes in the same file? If so, would I need to break all of the classes out into their own library files, or is there another way to handle this?

Thanks in advance,
-Chris
#2

[eluser]bretticus[/eluser]
The loader class is very specific on the conventions for CI Libs. To include and instantiate the class with one call requires this convention. So yes, break them into multiple files. You may have to modify the files to work as CI libs. Also note that you do not have to use the loader class. You can include and instantiate these classes using native PHP code.

EDIT, just took a peek at one of the files you mentioned. It shows 2 require statements for the other classes. Just make sure the paths are right and leave it that way. Just call the main class and you should be fine.
#3

[eluser]cmgmyr[/eluser]
Thanks for the reply. It looks like everything is working with the single file. I called it with native PHP code. The problem was that I didn't have the CA certificate installed for CURL that they needed. I will update the post again once I get everything 100%, so if anyone else needs it in the future it will be here.
#4

[eluser]bretticus[/eluser]
I did something similar with the google cart api recently. I stuck an autoload in the config file just to keep my code clean (and not having to include Google API files for the respective classes.) So i created a vendor folder in application and a googleapi.php config file with all my setting plus this autoload code:

Code:
/*
|--------------------------------------------------------------------------
| Google Lib Autoload
|--------------------------------------------------------------------------
|
| Autoload google libraries when using this config file.
|
|
*/

function google_api_autoload($class) {
    if ( stripos($class, 'google') !== FALSE ) {
        if (file_exists(APPPATH."vendors/google/".strtolower($class).EXT)) {
            include_once(APPPATH."vendors/google/".strtolower($class).EXT);
        }
    }
}

spl_autoload_register('google_api_autoload');

Now I can just load the config file and call classes such as:
Code:
$item = new GoogleItem('lbs. of ' . $products[$key]['name'],      // Item name
                                           $products[$key]['desc'], // Item      description
                                           $lbs, // Quantity
                                           $price); // Unit price

The autoload code handles loading all the necessary files.

Disclaimer:

The GoogleCart class has calls to require/include supplemental files with supplemental classes just like in your case. I did have to update the paths. For example, I updated the following line of code:

Code:
require_once(APPPATH.'vendors/google/xml-processing/gc_xmlbuilder.php');

I may have just as easily updated this line to:

Code:
require_once('xml-processing/gc_xmlbuilder.php');

since the xml-processing folder comes within the folder that encompasses these other google class files.
#5

[eluser]cmgmyr[/eluser]
Well, I finally got everything working with a few changes to my localhost and altering the API code a little bit. I worked up a simple library that should be very easy for someone to use. To read about it and download the files go to:

http://www.syracusecs.com/blog/2010/06/r...deigniter/

I hope that helps someone else in the future so they don't run into the same problems that I did.

-Chris




Theme © iAndrew 2016 - Forum software by © MyBB