Hi All,
I have a third party library which uses a external config file like this
application/library/api/API.php:
Code:
require_once "config.php";
error_log("Config var 1:" . $config_var); // Pure PHP Ok, CI Ok
class API {
function __construct () {
global $config_var;
error_log("Config var 2:" . $config_var); // Pure PHP Ok, CI BLANK!!
}
function doSomething (param1, param2) {
global $config_var_filename;
global $config_var_number;
$file = fopen($config_var_filename . '/' . param1, 'a+'); // Error
fwrite($file, $config_var_number + param2); // More errors
fclose($file); // And more errors
}
}
I've setup a library stub this way
application/library/LibAPI:
Code:
include dirname(__FILE__) . '/api/API.php';
class LibAPI extends API {
function __construct () {
parent::__construct();
}
}
Which I use in my controller like this
application/controllers/MyController:
Code:
class MyController extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('LibAPI');
$this->load->helper(array('url', 'form'));
....
}
public function index () {
$api = new LibAPI();
$api->doSomething('.TXT', 1); // ERROR!!!
...
}
...
The problem, as you can see in the included comments, is that under CI config parameters are not kept and, obviously, the API fails. I need to maintain the API code unchanged, so I cannot introduce CI specific code in it. What could I do?
Thank you.
Edo.