How to load a 3rd party library -> scope problems??

#1
[eluser]andjules[/eluser]
I'm having problems with the PHP library for the scribd api (follow the client libraries link).

When I run commands against the library OUTSIDE of CI, it performs fine. When I try to incorporate it inside CI and call it from a controller, I get undefined variable and undefined index PHP errors (it's definitely finding the library, instantiating the class, etc. as the errors are dealing with the XML response from Scribd). I'm not sure how the scope changes inside CI, so I was wondering if anyone might be able to explain that to my not-so-smart brain ;-)

[Interestingly, I was able to include some other Zend Framework libraries with no problems, using the 'lazy' method (create a helper that simply defines the base path, load the helper, then do a require once of the file)]

my controller code looks something like:
Code:
function scribd() {
            $this->load->helper('scribd');
            require_once "Scribd/scribd.php";
            // also tried: load_class('Scribd', FALSE);
            $scribd_api_key = "XXXYYYYXXXXYYY"; //add your own!
            $scribd_secret = "sec-123456789uvwxyz"; //add your own!
            $scribd = new Scribd($scribd_api_key, $scribd_secret);
            $newdoc = $scribd->getList();
            print_r($newdoc);
    }

the part of the Scribd library that deals with the response looks like this (note the author's comment... something's not quite right):
Code:
if($result['stat'] == "ok"){
                
                //This is shifty. Works currently though.
                $result = $this->convert_simplexml_to_array($result);
                if(urlencode((string)$result) == "

" && $this->error == 0){
                    $result = "1";
                    return $result;
                }else{
                    return $result;
                }
            }

and the convert_simplexml_to_array function from the Scribd library (the PHP errors trace to the "if($arr[$k]){" line):
Code:
public static function convert_simplexml_to_array($sxml) {
        $arr = array();
        if ($sxml) {
          foreach ($sxml as $k => $v) {
                if($arr[$k]){
                    $arr[$k." ".(count($arr) + 1)] = self::convert_simplexml_to_array($v);
                }else{
                    $arr[$k] = self::convert_simplexml_to_array($v);
                }
            }
        }
        if (sizeof($arr) > 0) {
          return $arr;
        } else {
          return (string)$sxml;
        }
    }
Thanks is advance for considering.


Messages In This Thread
How to load a 3rd party library -> scope problems?? - by El Forum - 04-22-2008, 10:01 AM
How to load a 3rd party library -> scope problems?? - by El Forum - 04-22-2008, 08:48 PM
How to load a 3rd party library -> scope problems?? - by El Forum - 04-22-2008, 10:41 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.