CodeIgniter Forums
Yahoo! BOSS Library - 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: Yahoo! BOSS Library (/showthread.php?tid=23310)



Yahoo! BOSS Library - El Forum - 10-06-2009

[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


Yahoo! BOSS Library - El Forum - 10-06-2009

[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.


Yahoo! BOSS Library - El Forum - 10-06-2009

[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!


Yahoo! BOSS Library - El Forum - 10-06-2009

[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


Yahoo! BOSS Library - El Forum - 10-07-2009

[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 ;-)


Yahoo! BOSS Library - El Forum - 10-07-2009

[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/


Yahoo! BOSS Library - El Forum - 10-07-2009

[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


Yahoo! BOSS Library - El Forum - 10-11-2009

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


Yahoo! BOSS Library - El Forum - 10-11-2009

[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/