![]() |
Passing single variable to library function - 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: Passing single variable to library function (/showthread.php?tid=23128) |
Passing single variable to library function - El Forum - 10-01-2009 [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? Passing single variable to library function - El Forum - 10-01-2009 [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. Passing single variable to library function - El Forum - 10-01-2009 [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. |