[eluser]matrim[/eluser]
I'm trying to create a library but am having problems to pass config values to it
I want to be able to pass values in 2 ways
1. user passes array of configuration parameters to set the values
or
2. user creates a config file (/system/application/config/myclass.php) and this is automatically picked up
So what I have so far is something like
Code:
class MyClass
{
public user = "";
public pass = "";
function MyClass($config = array())
{
if($config > 0)
{
this->initialize($config)
}
}
function initialize($config = array())
{
foreach ($config as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
function doSomething()
{
}
}
But it doesn't work either way.
I previously had it working passing a $params array directly into the constructor without the initialize function but want to be able to do it via a config file.
The docs say you can do this but I can't find an example of it to see if I'm doing it correctly. The above way is from me looking over the ci_email class in the build in libraries and trying to copy that