Welcome Guest, Not a member yet? Register   Sign In
Custom library config file
#4

(12-29-2015, 10:58 PM)wolfgang1983 Wrote:
(12-29-2015, 09:59 PM)edo Wrote: 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.

Codeigniter has own built in error log

http://www.codeigniter.com/user_guide/ge...rrors.html

http://www.codeigniter.com/user_guide/ge...og_message

And for writing file may be use codeigniter file helper

http://www.codeigniter.com/user_guide/he...elper.html

wolfgang1983,

Thank you for your answer.

I know about logging and file handling in CI, but that's not my problem.

Cheers.
Reply


Messages In This Thread
Custom library config file - by edo - 12-29-2015, 09:59 PM
RE: Custom library config file - by wolfgang1983 - 12-29-2015, 10:58 PM
RE: Custom library config file - by edo - 12-30-2015, 06:53 PM
RE: Custom library config file - by mwhitney - 12-30-2015, 09:00 AM
RE: Custom library config file - by edo - 12-30-2015, 07:25 PM
RE: Custom library config file - by mwhitney - 12-31-2015, 10:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB