Welcome Guest, Not a member yet? Register   Sign In
Autoload library with parameters
#1

[eluser]god_module[/eluser]
I'm using FX.php, a Filemaker library, together with Codeigniter to access a Filemaker DB. Library and config file are autoloaded in config/autoload.php.

This setup works perfectly well on my development machine (OS X, PHP 5.3.14). However, when I run the project on our dev server (Ubuntu Precise, PHP 5.3.10), it doesn't work. There seems to be an issue with the config parameters not being passed to the library. I get the following error messages:

Code:
Severity: Notice
Message:  Undefined index: dataServer
Filename: libraries/CIFX.php
Line Number: 9

Severity: Notice
Message:  Undefined index: dataPort
Filename: libraries/CIFX.php
Line Number: 9

Severity: Notice
Message:  Undefined index: dataType
Filename: libraries/CIFX.php
Line Number: 9

Severity: Notice
Message:  Undefined index: dataURLType
Filename: libraries/CIFX.php
Line Number: 9

My libraries/CIFX.php file looks like this:

Code:
require('FX.php');

class CIFX extends FX {

    function __construct ($params = array())
    {
        parent::__construct($params['dataServer'], $params['dataPort'], $params['dataType'], $params['dataURLType']);
    }

}

My config/CIFX.php file looks like this:

Code:
$config['dataServer'] = '192.168.1.10';
$config['dataPort'] = '80';
$config['dataType'] = 'FMPro7';
$config['dataURLType'] = '';
$config['dbuser'] = '';
$config['dbpassword'] = '';

According to the Codeigniter manual, this should be working.

Any help much appreciated!
#2

[eluser]PhilTem[/eluser]
Code:
public function __construct($config = array())
    {
        // No config provided?
        if ( ! is_array($config) )
        {
            // Load the config from the config file
            $this->config->load('config-name', TRUE);
            
            // And assign it to $config
            $config = $this->config->item('config-name');
        }
        
        parent::__construct($config['dataServer'], $config['dataPort'], $config['dataType'], $config['dataURLType']);
    }




Theme © iAndrew 2016 - Forum software by © MyBB