Welcome Guest, Not a member yet? Register   Sign In
[library] Loader
#1

[eluser]Peter Goodman[/eluser]
For some reason it seems that CI will include a library more than once if $this->load->library() is called for the same library. There are checks an balances in the code; however, they don't seem to be enough. This library provides a simple solution to the problem, and is something which I suggest should be implemented into CodeIgniter in the future.

Take note of the <subclass_prefix>

Code:
&lt;?php

/**
* Allow one to load the same library multiple times without
* the possibility of having an error that the class has already
* been declared.
*/

class <sublcass_prefix>Loader extends CI_Loader {
    
    static private $loaded = array();
    
    /**
     * We don't actually need to know the class name or anything special
     * about it such as where it comes from. All that matters is that a
     * class with this name or something similar has been loaded.
     */
    public function _ci_load_class($class, $params = NULL) {
        if(!in_array($class, self::$loaded)) {
            
            self::$loaded[] = $class;
            
            return parent::_ci_load_class($class, $params);
        }
        return;
    }
}


Messages In This Thread
[library] Loader - by El Forum - 08-07-2007, 11:08 AM
[library] Loader - by El Forum - 08-07-2007, 01:04 PM
[library] Loader - by El Forum - 08-07-2007, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB