Welcome Guest, Not a member yet? Register   Sign In
CI 2.0 Memcached library not loading in Model
#1

[eluser]whobutsb[/eluser]
Hello All,
I just began working on a new project in CI 2.0 and I think I ran in to a bug. I'm trying to add a memcache check in a model function that looks like this:

Code:
function select_user($UserID){
        
        if(!mem_get('UserID_'.$UserID)){    

            $HFMaster = $this->load->database('HFMaster', TRUE);
    
            $HFMaster->where('UserID', $UserID);
    
            $query = $HFMaster->get('users');
    
            mem_add('UserID_'.$UserID, $query->row());          
        }
        
        return mem_get('UserID_'.$UserID);
    }

The mem_get function is autoloading from a helper file I created called 'memcached_helper.php'. Which basically simplifies writing the library functions out like $this->memcached_library->get($key). Here is the code:
Code:
function load_memcache(){
    
    $CI =& get_instance();
    
    $CI->load->library('Memcached_library');
    
    return $CI;
}



function mem_get($key = NULL){
    
    return load_memcache()->Memcached_library->get($key);

}


If I run the model function as is I get the following error:
Code:
Fatal error: Call to a member function get() on a non-object in C:\wamp\www\SF2\application\helpers\memcached_helper.php on line 17

If I run the mem_get function in the controller it works fine, but as soon as I put them in the model I begin getting errors. Shouldn't in CI when I autoload helpers they should be available throughout the application? I have used my technique before in other applications using CI 1.7.2 and it hasn't been a issue. Thank you for the help!
#2

[eluser]whobutsb[/eluser]
It seems like all libraries and helpers that I autoload are not being called in my models. Has something changed in the way things are autoloaded in CI 2.0?




Theme © iAndrew 2016 - Forum software by © MyBB