Welcome Guest, Not a member yet? Register   Sign In
Undefined property when accessing model class
#14

[eluser]gor1lla[/eluser]
The problem is I didn't change any of the other files, except changing the url inside config.php.
I only added those 2 files.

If I changed my code to the following, there isn't any error.
Code:
class Test extends Controller {
    function Test()
    {
        parent::Controller();
    }
    
    function index()
      {
        $CI =& get_instance();
        $CI->load->model('category_model');
        $CI->category_model->get(1);
    }
}

I did a print_r($CI) inside the Loader library's model function, category_model is there.
I can even call the model via $CI->category_model and no error.

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

        if ($model == '')
        {
            return;
        }
    
        // Is the model in a sub-folder? If so, parse out the filename and path.
        if (strpos($model, '/') === FALSE)
        {
            $path = '';
        }
        else
        {
            $x = explode('/', $model);
            $model = end($x);            
            unset($x[count($x)-1]);
            $path = implode('/', $x).'/';
        }
    
        if ($name == '')
        {
            $name = $model;
        }
        
        if (in_array($name, $this->_ci_models, TRUE))
        {
            return;
        }
        
        $CI =& get_instance();
        if (isset($CI->$name))
        {
            show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
        }
    
        $model = strtolower($model);
        
        if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
        {
            show_error('Unable to locate the model you have specified: '.$model);
        }
                
        if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
        {
            if ($db_conn === TRUE)
                $db_conn = '';
        
            $CI->load->database($db_conn, FALSE, TRUE);
        }
    
        if ( ! class_exists('Model'))
        {
            load_class('Model', FALSE);
        }

        require_once(APPPATH.'models/'.$path.$model.EXT);

        $model = ucfirst($model);
                
        $CI->$name = new $model();
        $CI->$name->_assign_libraries();
        
        $this->_ci_models[] = $name;

        // tracing
        print_r($CI);
        $CI->category_model->get(1);
    }

I am suspecting that the $CI is not referenced properly.
Is $this same as $CI =& get_instance() ?
Could it be a php.ini setting that is affecting this?


Messages In This Thread
Undefined property when accessing model class - by El Forum - 08-20-2010, 04:34 AM
Undefined property when accessing model class - by El Forum - 08-20-2010, 07:29 AM
Undefined property when accessing model class - by El Forum - 08-20-2010, 07:35 AM
Undefined property when accessing model class - by El Forum - 08-20-2010, 08:34 AM
Undefined property when accessing model class - by El Forum - 08-20-2010, 10:04 AM
Undefined property when accessing model class - by El Forum - 08-20-2010, 11:39 PM
Undefined property when accessing model class - by El Forum - 08-20-2010, 11:43 PM
Undefined property when accessing model class - by El Forum - 08-21-2010, 12:09 AM
Undefined property when accessing model class - by El Forum - 08-21-2010, 03:44 AM
Undefined property when accessing model class - by El Forum - 08-22-2010, 01:54 AM
Undefined property when accessing model class - by El Forum - 08-22-2010, 03:08 AM
Undefined property when accessing model class - by El Forum - 08-22-2010, 04:31 AM
Undefined property when accessing model class - by El Forum - 08-22-2010, 12:23 PM
Undefined property when accessing model class - by El Forum - 08-22-2010, 03:56 PM
Undefined property when accessing model class - by El Forum - 09-03-2010, 12:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB