Welcome Guest, Not a member yet? Register   Sign In
A little help needed with creating a library
#1

[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


Messages In This Thread
A little help needed with creating a library - by El Forum - 03-04-2009, 11:53 AM
A little help needed with creating a library - by El Forum - 03-04-2009, 12:02 PM
A little help needed with creating a library - by El Forum - 03-04-2009, 05:58 PM
A little help needed with creating a library - by El Forum - 03-04-2009, 08:21 PM
A little help needed with creating a library - by El Forum - 03-05-2009, 01:32 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 02:04 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 02:40 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 02:44 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 03:59 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 04:04 AM
A little help needed with creating a library - by El Forum - 03-05-2009, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB