Welcome Guest, Not a member yet? Register   Sign In
making autoload model with ease.
#1

[eluser]xeroblast[/eluser]
a simple solution making your autoloading of model has a new object name you prefer.

loading a model with a new object name is like this...

Code:
$this->load->model('model_name','new_object_name');

what if that model you want to load should be in autoload coz you want to use it globally?
in autoloading of model, libraries, and etc... the code used is...

Code:
for example:
$autoload['model'] = array('model1','model2');

and that loading of models wont give you a new object name. so how will i autoload models with new object name? its easy.

open your
Quote:application/libraries/Loader.php
and look for something that is similar below...

Code:
function model($model, $name = '', $db_conn = FALSE)
    {        
        if (is_array($model))
        {
            foreach($model as $babe)
            {
                $this->model($babe);    
            }
            return;
        }

and change it to something like this.

Code:
function model($model, $name = '', $db_conn = FALSE)
    {        
        if (is_array($model))
        {
            foreach($model as $babe => $chick)
            {
                if (is_int($babe)) {
                    $this->model($chick);
                } else {
                    $this->model($babe,$chick);
                }
            }
            return;
        }

and autoload your models like this...

Code:
$autoload['model'] = array('model1' => 'object_name1','model2','model3' => 'object_name3');

so you can autoload models with their own object name. i hope they will include this in their next release. CIAO...




Theme © iAndrew 2016 - Forum software by © MyBB