简体   繁体   English

带参数的Codeigniter自动加载库

[英]Codeigniter autoload library with parameters

I'm using FX.php together with Codeigniter to access a Filemaker DB. 我将FX.phpCodeigniter一起使用来访问Filemaker数据库。 Library and config file are autoloaded in config/autoload.php. 库和配置文件会自动加载到config / autoload.php中。

This setup works perfectly well on my development machine (OS X, PHP 5.3.14). 此设置在我的开发机器(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. 但是,当我在开发服务器(Ubuntu Precise,PHP 5.3.10)上运行项目时,它不起作用。 There seems to be an issue with the config parameters not being passed to the library. config参数未传递到库似乎存在问题。 I get the following error messages: 我收到以下错误消息:

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: 我的libraries / CIFX.php文件如下所示:

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: 我的config / CIFX.php文件如下所示:

$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. 根据Codeigniter手册 ,这应该可以正常工作。

Any help much appreciated! 任何帮助,不胜感激!

you need to be Passing Parameters When Initializing Your Class 您需要在初始化类时传递参数

$params = array(
    'dataServer' =>  $this->config->item('dataServer');, 
    'dataPort'   =>  $this->config->item('dataPort');
);

$this->load->library('CIFX ', $params);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM