Welcome Guest, Not a member yet? Register   Sign In
Need a little help with a config file for my custom library...???
#11

[eluser]angelleye[/eluser]
Looks like that was the problem. I renamed my files accordingly and now I'm getting data into $DataArray in my library. Thanks!!
#12

[eluser]angelleye[/eluser]
One more question for you in relation to this original question, if you don't mind, please.

I'm storing my own API credentials in my config file and loading them accordingly to make calls to PayPal. That's all working great now (thanks again).

When making calls to PayPal on behalf of a 3rd party, though, I'd still use my own credentials but then I'd pass in a dynamic value to distinguish who the call is being made for. This is generally pulled from a database based on the user signed in to the application.

In such a case it seems that I have 2 choices:

1) Revert back to the original way I had it working where I used the config class to pull data out of the config file. Then also load up a model from the same method in my controller that pulls the user ID I need and include all the data in the config array that I pass in directly when I load the library.

2) Load up a model from within my config file so that I can pull necessary data and still load everything up automatically using the config file method without loading options directly.

Would option 2 even work out ok? If so, is it considered an ok practice? Which method should I choose?

Any info is great as always. Thanks!
#13

[eluser]tomcode[/eluser]
I'll keep the config file as plain data holder, no code, the model call probably won't work anyway.

You could do :

Code:
class Paypal_ap {

    var $defaults = array('x', 'y');
    
    var $x = NULL;
    var $y = NULL;
    var $z = NULL;
    
    function Paypal_ap($params = array())
    {
      $this->initialize($params);
    }

    function initialize($params = array())
    {
        foreach($params as $key => $param)
        {
            if(isset($this->$key))
            {
                $this->$key = $param;
            }
        }
    }

    function reset()
    {
        $CI =& get_instance();
        
        $values = array();
        
        foreach($this->defaults as $key)
        {
            $values[$key] = $CI->config->item($key);
        }
        
        $this->initialize($values);
    }
}

Now You can have a fully automated run, You can set values from the controller and You have a convenience function to easily return to a default state.




Theme © iAndrew 2016 - Forum software by © MyBB