Welcome Guest, Not a member yet? Register   Sign In
Using a library more than once
#1

[eluser]TheseAreTheFables[/eluser]
Hello,

I created a library which allows managing file paths. It works a bit like this:

$this->load->library("file_handler", array("filepath" => "/some/path.txt");
echo $file_handler->name();
echo $file_handler->extension();
// etc...

My problem is that sometime I need to use this library more than once, on two or more file paths. In that case, how can I do that with CodeIgniter? Is there some way to create several instances of a library instead of "loading" it?
#2

[eluser]bubbafoley[/eluser]
just give names to the libraries via the third parameter

Code:
$this->load->library('file_handler', array('filepath'=>'/some/path.txt'), 'file1');
$this->load->library('file_handler', array('filepath'=>'/some/other/path.rtf'), 'file2');

echo $this->file1->extension(); // txt
echo $this->file2->extension(); // rtf
#3

[eluser]TheseAreTheFables[/eluser]
Exactly what I needed, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB