CodeIgniter Forums
[SOLVED] How to get an instance of a specific model from _ci_models in the loader class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [SOLVED] How to get an instance of a specific model from _ci_models in the loader class? (/showthread.php?tid=38583)



[SOLVED] How to get an instance of a specific model from _ci_models in the loader class? - El Forum - 02-12-2011

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


[SOLVED] How to get an instance of a specific model from _ci_models in the loader class? - El Forum - 02-12-2011

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