i’m trying to separate paypal config info from application/paypal_library file. Basically the config info are API_username, API_pwd, API_signiture etc.
The original structure is like this:
class Paypal_library {
protected $ci;
public $API_UserName = xxx;
public $API_Password = xxx;
public $API_Signature = xxx;
...
...
function __construct() {
$this->ci = & get_instance();
}
otherfunctions
so I move these variables in a new config file called config/paypal_config.php.
and put
$config['paypal_api_username'] =xxx;
$config['paypal_api_password'] = xxx;
$config['paypal_api_signature'] = xxx;
But i got a problem when i call this config file in paypal_library.php.
I used:
protected $ci;
$CI = & get_instance();
$CI->config->load("paypal_config",TRUE);
$config = $CI->config->item('paypal_config');
public $API_UserName = $config['paypal_api_username'];
public $API_Password = $config['paypal_api_password'];
public $API_Signature = $config['paypal_api_signature'];
...
...
function __construct() {
$this->ci = & get_instance();
}
But this doesn’t work, because it seems that i cannot put $CI=&get_instance() before constructor? However, if i put them inside constructor, paypal can’t find those variables during payment process.
so how can i implement paypal_config file here?
Thanks
You should set the properties in the constructor.
A class can only contain method and property definitions.
The operations in your example before the API property definitions are syntactically incorrect and will cause a parse error.