Welcome Guest, Not a member yet? Register   Sign In
Yahoo! BOSS Library
#1

[eluser]Fabdrol[/eluser]
Hi Guys!

I'm writing a (simple) Yahoo! BOSS Library for CodeIgniter.
Just ran into a little problem.

According to the User Guide, it's possible to pass arguments to a lib using the loader Class...

Quote:Passing Parameters When Initializing Your Class

In the library loading function you can dynamically pass data as an array via the second parameter and it will be passed to your class constructor:

Code:
$params = array('type' => 'large', 'color' => 'red');

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

If you use this feature you must set up your class constructor to expect data:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Someclass {

    function Someclass($params)
    {
        // Do something with $params
    }
}

?>

Now, I tried to implement this, but I keep getting errors that the constructor misses it's parameters.

My code:
First try:
Code:
class Yahoo {

  function __construct($api_key) {
    $this->api_key = $api_key;
  }

}

Second try
Code:
class Yahoo {

  function Yahoo($api_key) {
    $this->api_key = $api_key;
  }

}

Loader part:
Code:
$this->load->library('yahoo', $api_key);

I hope somebody knows why it doesn't work!

Thanks!
Fabian
#2

[eluser]Zack Kitzmiller[/eluser]
I've never really been able to get this to work right, and have tried several times.

I ended up using a $config[] array.
#3

[eluser]Fabdrol[/eluser]
Yeah, I've got a 'temp' solution by caching the CI instance and fetching a $config item..
But I really want it the 'normal' way. Please, CI Folkes! talk to us!
#4

[eluser]renownedmedia[/eluser]
I saw a post mention this not to long ago... I think it was determined that ellislab broke that functionality a few versions ago and nobody really missed it
#5

[eluser]Fabdrol[/eluser]
That's quite fubar... So there isn't any way to make a library work like a 'regular' php class?
I'll dive into that loader class... don't like this!

thanks for your comments!
Fabian

ps.: strange that there isn't any CI crew to say anything on this ;-)
#6

[eluser]pistolPete[/eluser]
As of CI 1.7.0, the passed parameters must be in an array.
I submitted a bug report back then: http://codeigniter.com/bug_tracker/bug/5709/
#7

[eluser]InsiteFX[/eluser]
In the library loading function you can dynamically pass data as an array via the second parameter and it will be passed to your class constructor:

Code:
$params = array('type' => 'large', 'color' => 'red');

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

Enjoy
InsiteFX
#8

[eluser]Fabdrol[/eluser]
Great, got it worked out now.
I'll post the CI Boss lib online with some documentation today.
#9

[eluser]Fabdrol[/eluser]
As promised, I posted the project online.
2 versions: one for CI, and one regular PHP class.

I'll be updating the Lib during time, as it is for a client project.
The project page:

http://code.google.com/p/yahoo-boss-php/




Theme © iAndrew 2016 - Forum software by © MyBB