Welcome Guest, Not a member yet? Register   Sign In
Passing single variable to library function
#1

[eluser]Unknown[/eluser]
I've tried searching both the forum and google for this, but come up with nothing.

In my design I would like when loading the library to pass a single variable (id) to it. The user guide says that libraries can be initialized with arrays so I could do something like:

Code:
$this->load->library('Mylib', array('id' => $id));

But from a estetic point of view (and so I dont have to remember to wrap it in an array) I'd rather do:

Code:
$this->load->library('Mylib', $id);

Would that work?
#2

[eluser]rogierb[/eluser]
Is is up to you. If you want an array use an array, if you only need a single variable, use asingle variable.
Just make sure your constructor handles the type you have chosen.

Short answer: yes.
#3

[eluser]Unknown[/eluser]
I thought that it would work that way, but since the user guide states

Quote: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

It made me think that maybe the library constructors would accept ONLY arrays.

Thanks for the quick clearification.




Theme © iAndrew 2016 - Forum software by © MyBB