Welcome Guest, Not a member yet? Register   Sign In
how to access core config files from the extended library
#1

[eluser]Unknown[/eluser]
Hey,
I have little problem in loading codigniter core config files from one of the extended library.

for example:- I have extended the "image_lib" as MY_image_lib and now i want to use codigniter core config files form My_image_lib ..... How can i do this......

urgent...... Thanks in advance
#2

[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..




Theme © iAndrew 2016 - Forum software by © MyBB