Welcome Guest, Not a member yet? Register   Sign In
phpFlickr as a Library
#1

[eluser]Unknown[/eluser]
I'm new to CI and I've been fooling around with it. I really like what I see but i was wondering if I could get some help.

I've been trying to load the phpFlickr class as a lib and i keep on getting the "Unable to load the requested class: phpflickr". It's in the libraries folder. I've tried passing the params in different ways but no luck.

This is the way i'm loading it in my controller
Code:
$params = array('api_key' => '<MyAPI-KEY>', 'secret' => NULL, 'die_on_error' => 'false' );

        $this->load->library('phpFlickr', $params);

Can anybody see what i'm doing wrong.

Thanks

Rik
#2

[eluser]gerben[/eluser]
I had the same problem, but solved it by hardcoding my API-key in the class:

function phpFlickr ($api_key = '<MY API KEY>', $secret = NULL, $die_on_error = false)

Not the most elegant way, but it works.

Also make sure the PEAR-library folder is in your libraries folder, otherwise phpFlickr won't find it.
#3

[eluser]bugboy[/eluser]
after looking at this i still personally get the phpFlickr class to load

i get

An Error Was Encountered
Unable to load the requested class: phpflickr


I've hand coded my api into the class to see if that works with no joy

any ideas
#4

[eluser]bugboy[/eluser]
I forgot to put a capital letter on the front of the class

So it loads now but i'm not getting this.


Severity: Notice

Message: Undefined property: Flickr_test::$phpFlickr

Filename: controllers/flickr_test.php

Line Number: 18

Fatal error: Call to a member function photos_getRecent() on a non-object in /home/fhlinux162/o/our-atelier.co.uk/user/htdocs/application/controllers/flickr_test.php on line 18

I'm uing the example the phpFlickr gives
#5

[eluser]Chris Newton[/eluser]
in your controller are you calling a method from the library? If so, you'll need to call it like so:

$this->phpflickr->photos_getRecent();
#6

[eluser]bugboy[/eluser]
yeah i am which is why its weird.
#7

[eluser]Chris Newton[/eluser]
Can you post your controller code, or PM it.
#8

[eluser]bugboy[/eluser]
right it was because i was using so you were right ha ha ha Wink

Code:
$this->phpFlickr->photos_getRecent();

instead of

Code:
$this->phpflickr->photos_getRecent();

Now thats working i'm not getting anything back at all which is now my next challange.

posted code

Code:
function index()
    {
    $this->load->library('phpFlickr');
    
    $recent = $this->phpflickr->photos_getRecent();
    print_r($recent);
    
    foreach ($recent['photo'] as $photo) {
        $owner = $this->phpflickr->people_getInfo($photo['owner']);
        echo "<a href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>";
        echo $photo['title'];
        echo "</a> Owner: ";
        echo "<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>";
        echo $owner['username'];
        echo "</a><br>";
    }
    
    }

Its now throwing this error but i understand its because the foreach loop is empty


A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: controllers/flickr.php

Line Number: 20
#9

[eluser]Chris Newton[/eluser]
So nothing happens when you var_dump it... nothing's returned?

I guess the first thing I'd try is running the library outside of CodeIgniter and see if I get any traction.
#10

[eluser]Unknown[/eluser]
I had almost the same problem... i just found out, that the $params are not given correctly.

So i tried this:
Code:
$params['api_key'] = '<MY_API_KEY>';
    $params['secret'] = '<MY_SECRRET>';
    $this->load->library('phpflickr');
    $this->phpflickr->api_key = '<MY_API_KEY>';
    $this->phpflickr->secret = '<MY_SECRET>';
    $this->phpflickr->setToken('<MY_TOKEN>');
    
    $this->phpflickr->enableCache(
        "db",
        "mysql://user:pass@localhost/phpflickr",
        "600"
    );


okey... i had to set the apikey and the secret twice... but this just works out fine for me. =)




Theme © iAndrew 2016 - Forum software by © MyBB