Welcome Guest, Not a member yet? Register   Sign In
[Q] cannot pass arguments to __constructor with load->library
#3

[eluser]Evil Wizard[/eluser]
it is possible to pass arguments to the library classes, however the arguments have to be passed in as an array

controller snippet...
Code:
...
    $this->load->library('library_class', array('arg1', 'arg2' => true), 'library_object_name');
...

library snippet...
Code:
...
public function __construct($arrArgs)
{
    print_r($arrArgs);
}
...

the loader class creates a new instance of the library which suggest that multiple configured instances of the library should be available, but i suspect that CI updates the links to other objects with the current instance of the libraries.

an alternative to this would be...

controller snippet...
Code:
...
    $this->load->library('library_class');
    $this->library_class->initialize('arg1', TRUE);
...

library snippet...
Code:
...
public function initialize($arg1, $arg2)
{
    echo arg1;
    echo arg2;
}
...


Messages In This Thread
[Q] cannot pass arguments to __constructor with load->library - by El Forum - 05-01-2009, 08:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB