CodeIgniter Forums
Variable that points to a library class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Variable that points to a library class? (/thread-57353.html)



Variable that points to a library class? - El Forum - 03-08-2013

[eluser]JackU[/eluser]
How can i do this so it works? I wan´t the $myservice variable to point to the loaded webservice.

if ($message=="a")
{
$this->CI->load->library('webservice_a');
$myservice = $this->CI->webservice_a;
}
else
{
$this->CI->load->library('webservice_b');
$myservice = $this->CI->webservice_b;
}

$data = $myservice->loadstuff();




Variable that points to a library class? - El Forum - 03-08-2013

[eluser]Aken[/eluser]
You can assign your own property name when loading a class.

Code:
$this->load->library('webservice_a', NULL, 'myservice');

// Access it with:
$this->myservice->loadstuff();