Welcome Guest, Not a member yet? Register   Sign In
Loading library from name
#1

Hi,

I have trouble to use a library that I load depending on a variable data.

$mylibrary = 'Custom_Lib';
$mymethod = 'Method1';
//those two are retreived from a database.

//After I use the method:

$this->load->library($mylibrary);
$this->$mylibrary->$method();

//I have an error that I'm calling a method on a non object...

I've tried also
class_alias(strtolower($mylibrary), 'useclass');
$this->useclass->$method($record);

//same problem...

Any one have an advise to call a special library/method from dynamicly ?

Thanks for your help,

Yannick
Reply
#2

Does it work if you access it directly instead of using a variable?

One thing that may cause that is when you use $this->library_name, "library_name" I believe should be lower case. You're using $mylibrary, where the variables value isn't lower case.

So it just might need something like:
$this->load->library($mylibrary);
$mylibrary = strtolower($mylibrary); //force to lower case before accessing
$this->$mylibrary->$method();

Did you try it using the actual names instead of variables to test?
Reply
#3

Thanks CroNIX,

Your solution was the right one !

Always use lowercase for library call...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB