[eluser]hadinug[/eluser]
hi... maybe this can help you
yesterday I found a problem seem as yours, i want to access file config from another directory for ex: application/libraries/config/ , so I create new library,, just little editing in library/confing.php..
first: i create file hconfig.php in folder application/libraries/
and write this
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class hconfig {
var $config = array();
var $count;
var $array;
var $is_loaded = array();
function hconfig() {
$this->config = & get_config();
log_message('debug', "Config Class Initialized");
}
/**
* load()
* $path . path name where you take config file
* file . file name of your config
*/
function load($path = '', $file = '', $use_sections = FALSE, $fail_gracefully = FALSE) {
if (isset($path)) {
$file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
if (in_array($file, $this->is_loaded, TRUE)) {
return TRUE;
}
if (!file_exists(APPPATH . $path . $file . EXT)) {
if ($fail_gracefully === TRUE) {
return FALSE;
}
show_error('The configuration file ' . $file . EXT . ' does not exist.');
}
include(APPPATH . $path . $file . EXT);
// return number of config array
$this->count = count($config);
// return array name
$this->array = $config;
if (!isset($config) OR !is_array($config)) {
if ($fail_gracefully === TRUE) {
return FALSE;
}
show_error('Your ' . $file . EXT . ' file does not appear to contain a valid configuration array.');
}
if ($use_sections === TRUE) {
if (isset($this->config[$file])) {
$this->config[$file] = array_merge($this->config[$file], $config);
} else {
$this->config[$file] = $config;
}
} else {
$this->config = array_merge($this->config, $config);
}
$this->is_loaded[] = $file;
unset($config);
log_message('debug', 'Config file loaded: config/' . $file . EXT);
return TRUE;
}
}
function item($item, $index = '') {
if ($index == '') {
if (!isset($this->config[$item])) {
return FALSE;
}
$pref = $this->config[$item];
} else {
if (!isset($this->config[$index])) {
return FALSE;
}
if (!isset($this->config[$index][$item])) {
return FALSE;
}
$pref = $this->config[$index][$item];
}
return $pref;
}
function set_item($item, $value) {
$this->config[$item] = $value;
}
}
and how it's work....?
ex: you can create a new file config,,, for example: mylibrary_config.php in folder application/libraries/config/
write in application/libraries/config/mylibrary_config.php
Code:
$config['name'] = 'hadi nugroho';
$config['country'] = 'indonesia';
in your controller fuction
Code:
$this->load->library('hconfig');
$this->hconfig->load('libraries/config/', 'mylibrary_config'. EXT);
echo $this->hconfig->item('name').'<br/>';
echo $this->hconfig->item('country');
i wish it's can help you..