CodeIgniter Forums
Including non CodeIgniter scripts - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Including non CodeIgniter scripts (/showthread.php?tid=19114)

Pages: 1 2


Including non CodeIgniter scripts - El Forum - 06-27-2010

[eluser]RickP[/eluser]
I think my question/problem is similar.

I have installed an outside library which works fine except that I don't know how to pass values to it. $this->load->library() seems to allow the passing of only one value but the library I'm using will accept six values (all have good defaults).

If I just want the defaults it works fine.

How can I pass multiple values?


Including non CodeIgniter scripts - El Forum - 06-28-2010

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html


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
    }
}

?>
You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name and store it in your application/config/ folder. Note that if you dynamically pass parameters as described above, the config file option will not be available.



Including non CodeIgniter scripts - El Forum - 06-28-2010

[eluser]RickP[/eluser]
I <b>have</b> read the documentation. It doesn't work for me.

I create an array of two items which I pass as the second argument to $this->load->library() but within the class constructor func_num_args() returns 0. Shouldn't it return 1?

UPDATE:

I found the problem. The library had been loaded in the controller so when I loaded it in the model (with the arg) the loading was ignored.


Including non CodeIgniter scripts - El Forum - 06-28-2010

[eluser]danmontgomery[/eluser]
Yes... Can you post some code?