Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] How to get an instance of a specific model from _ci_models in the loader class?
#1

[eluser]Vheissu[/eluser]
In the main Codeigniter class there is an array that is populated with all models that are currently loaded called '_ci_models'. How do I go about getting an instance of a model, I know it's possible to do so with a library and is done in the helper function for getting form validation errors.

I tried the following, but doesn't appear to work. The array of models appears to be indexed, where the _ci_classes array isn't indexed.

Code:
function &get;_auth_class()
{
    $CI =& get_instance();

    $return = FALSE;

    if ( ! isset($CI->load->_ci_models) OR  ! in_array('auth', $CI->load->_ci_models) )
    {
        return $return;
    }

    $object = $CI->load->_ci_models['auth'];

    if ( ! isset($CI->$object) OR ! is_object($CI->$object) )
    {
        return $return;
    }

    return $CI->$object;
}

I need to get an instance of the model to get values stored inside of an array of errors. Is there an easier way to access model variables without assigning by reference like the above function?
#2

[eluser]Vheissu[/eluser]
Nevermind, I solved this. I realised I can just load the model and go $CI->modelname instead. Lol, sorry.




Theme © iAndrew 2016 - Forum software by © MyBB